home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / CRS / crs50.d81 / issue3 < prev    next >
Text File  |  2009-10-10  |  127KB  |  3,156 lines

  1.  
  2.                    ########
  3.              ##################
  4.          ######            ######
  5.       #####
  6.     #####  ####  ####      ##       #####   ####  ####  ####  ####  ####   #####
  7.   #####    ##    ##      ####     ##   ##   ##  ###     ##    ####  ##   ##   ##
  8.  #####    ########     ##  ##    ##        #####       ##    ## ## ##   ##
  9. #####    ##    ##    ########   ##   ##   ##  ###     ##    ##  ####   ##   ##
  10. #####  ####  ####  ####  ####   #####   ####  ####  ####  ####  ####   ######
  11. #####                                                                     ##
  12.  ######            ######        Volume 1 - Issue 3
  13.    ##################              July 15, 1992
  14.        ########
  15.  
  16. =============================================================================
  17. Editor's Notes:
  18. by Craig Taylor (duck@pembvax1.pembroke.edu)
  19.  
  20.   Here's over 3000 lines of hacking articles & such... Sorry about the length
  21. as some of the articles ran a bit overboard.  Included within is a discussion of
  22. the KERNAL routines, an examination of Rasters, and a package of burst routines
  23. for use in your own programs. If you've got any ideas for articles etc that  
  24. you'd like to see or want to hear more on a certain topic feel free to email 
  25. me. 
  26.  
  27.   I'm pleased to introduce the Demo Corner where each month we'll report 
  28. how to achieve some of the graphic and sound effects that are present in 
  29. many demos that are wondered about.
  30.  
  31.   Note: The article concerning programming and usage of the 1351 mouse has
  32. been delayed until the next issue due to time and length constraints.
  33.  
  34.   This file is available via anonymous ftp at tybalt.caltech.edu under 
  35. pub/rknop/hacking.mag.  Back issues of C= Hacking are also located there.
  36.  
  37. **************** WARNINGS, UPDATES, BUG REPORTS, ETC... **********************
  38.  
  39.   OOPS - In the last issue of C= Hacking in Mark Lawrence's File Splitter a line
  40. inadvertantly got chopped off.  The following code should be fixed between the 
  41. comments that are listed:
  42.  
  43. [.
  44.   .
  45.    .] 
  46.    { Make EXTENSION a string representation of COUNT, to be added to the
  47.       OutFileName to make things a tad easier}
  48.  
  49.     OutFileName := Concat(NewFile,'.',Copy('00',1,3-Length(Extension)),
  50.                    Extension);   {**THIS IS THE STATEMENT...**}
  51.  
  52.     { Create filename based on which part we're up to }
  53. [.
  54.   .
  55.    .]
  56.  
  57. =============================================================================
  58. Note: Permission is granted to re-distribute this "net-magazine", in whole,
  59.   freely for non-profit use. However, please contact individual authors for
  60.   permission to publish or re-distribute articles seperately.
  61.  
  62.       *** AUTHORS LISTED BELOW RETAIN ALL RIGHTS TO THEIR ARTICLES ***
  63. =============================================================================
  64. In This Issue:
  65.  
  66. Learning ML - Part 3
  67.  
  68.   In this edition we take a look at reading and writing commands to the disk
  69. drive, including reading the disk directory and error channel. This article
  70. parallels the discussion of the C=128 and C=64 KERNAL jump tables of available
  71. routines. Written by Craig Taylor.
  72.  
  73. The Demo Corner: Missing Cycles
  74.  
  75.   Everybody knows that there are 63 cycles available to the C64 processor
  76. on each scan line, except for one which only provides 23 cycles. But what
  77. happens when we add sprites and why ? Written by Pasi 'Albert' Ojala.
  78.  
  79. KERNAL 64/128
  80.  
  81.   The C=128 and C=64 jump table points to many valuable system routines is
  82. discussed and examined in detail. Written by Craig Taylor.
  83.  
  84. 64K VDC RAM and an alternate GEOS128 Background Screen
  85.  
  86.   Standard GEOS only uses the first 16K of your VDC screen.  If you have 64K
  87. of VDC RAM, and want to write an 80-column only application, you can put some
  88. of the additional VDC RAM to use as a replacement for the standard GEOS
  89. background screen.  And, in the bargain, you get an additional 16K of
  90. application FrontRAM to use! Written by Robert Knop.
  91.  
  92. GeoPaint File Format
  93.  
  94.   Written by Bruce Vrieling, this article provides an in depth description of
  95. exactly how geoPaint stores its graphic images on disk. It examines the
  96. concept of VLIR files, how graphics data is laid out on screen (from both
  97. geoPaint and the VIC's perspective), and geoPaint's graphics compression
  98. techniques.
  99.  
  100. Rasters - What They Are and How to Use Them
  101.   
  102.   Written by Bruce Vrieling, this article provides an introduction to creating
  103. special on-screen effects using the technique of raster interrupts. The
  104. basics are examined, including what they are, and how to program them. This
  105. article should provide a good starting point for someone wanting to get
  106. their feet wet in raster programming.
  107.  
  108. Bursting Your 128: The Fastload Burst Command
  109.  
  110.   Written by Craig Bruce this article covers the Fastload burst command of the
  111. 1571 and 1581 disk drives.  The Fastload command operation and protocol are
  112. discussed and a package for using the Fastload command to read regular
  113. sequential files at binary program loading speeds is presented.  To demonstrate
  114. the package, a file word counting utility is implemented and the "commented"
  115. code is included.
  116.  
  117. ============================================================================
  118. Learning ML - Part 3
  119. by Craig Taylor (duck@pembvax1.pembroke.edu)
  120.  
  121.   Last time we used a routine at $FFD2 which would print out the character code
  122. contained within the accumalator.  That location will always print the character
  123. out regardless of VIC-20, C=64, C=128 and even PET because Commodore decided 
  124. to set up some locations in high memory that would perform routines that are
  125. commonly needed.  
  126.  
  127.   Take a look now at the KERNAL 64/128 article and glance over some of the 
  128. routines and their function / purpose. This article is meant to be a companion
  129. to that article so you may want to flip back and forth as the discussion 
  130. of the program listed below is discussed.
  131.  
  132.   Note that I've borrowed Craig Bruce's notation of having listings inside. To
  133. extract the source that follows enter the following command on a Unix system:
  134.  
  135. grep '^\.@...\!' Hack3 | sed 's/^.@...\!.//' | sed 's/.@...\!//' >dir.asm
  136.  
  137. .@001! ;
  138. .@002! ; Set up computer type for computer-dependant code / 
  139. .@003! ;    Only used in displaying # routine / start of assembly setting.
  140. .@004! ; BUDDY format.
  141. .@005! ;
  142. .@006! computer = 128             ; Define as either 64 or 128.
  143.  
  144.   For both c64 and c128 users the following code works.  Within the code is 
  145. conditional assembly which means it will work on either computer assuming that
  146. the computer is equal to either 128 or 64.
  147.  
  148. .@007! 
  149. .@008! .if computer-64            ;** if computer not c64 then
  150. .@009!       .org $1300          ;   and also make sure in BANK 15 when calling
  151. .@010!                           ;   these routines.
  152. .@011! .else                      ;** else if _is_ c64, then
  153. .@012!       .org $c000
  154. .@013! .ife                       ;** end of computer-dependant code.
  155.  
  156.   Because of this (the source is in BUDDY format) the C64 and C128 are set to 
  157. assemble at different memory locations. On the C64, $c000 is 49152. On the C128 
  158. it is at 4864. Note for the C128 it is necessary to do a BANK15 before executing
  159. the code.
  160.           
  161. .@014!       .mem                ; - assemble to memory.
  162.  
  163.   This tells the assembler to actually put the code into memory.
  164.  
  165. .@015!
  166. .@016! ;;-----------------------------------------------------------------------
  167. .@017! ;; KERNAL EQUATES
  168. .@018! ;;---------------------------------------------------------------------
  169. .@019! 
  170. .@020! setnam = $ffbd
  171. .@021! setlfs = $ffba
  172. .@022! open   = $ffc0
  173. .@023! close  = $ffc3
  174. .@024! chkin  = $ffc6
  175. .@025! chrin  = $ffcf
  176. .@026! bsout  = $ffd2
  177. .@027! clrch  = $ffcc
  178. .@028!
  179.  
  180.   These are the KERNAL routines we will actually be using. Their actual 
  181. use will be documented when we come across them within the code.  
  182.  
  183. .@029! ;;-----------------------------------------------------------------------
  184. .@030!
  185. .@031! temp   = 253
  186. .@032! charret = $0d
  187. .@033! space = $20
  188. .@034!
  189.  
  190.   Temp is set up to just be a temporary location in zero-page. Location 253 on
  191. both the C64 and C128 is unused.  Charret stands for the carriage return
  192. character and is the equivlent of a chr$(13). Space stands for the code for a 
  193. space (a chr$(32))
  194.  
  195. .@035! ;;---------------------------------------------------------------------
  196. .@036!
  197. .@037! start = *
  198. .@038!
  199. .@039!    jsr read'dir       ; Initial jump table -- Note: Will read error after
  200. .@040!    jmp read'err       ;     showing directory.
  201. .@041!
  202.  
  203.   You'll see code like this a lot -- Basically we're building what is known as a
  204. jump table. That way if we add more code to the directory or error routine we
  205. don't have to worry about our SYS call's changing. To read the directory just
  206. SYS base, to read the error channel just SYS base+3 (where BASE is 49152 on the
  207. C64, 4864 on the 128)... 
  208.  
  209.   Also the JSR JMP combination may seem a little strange but what we are doing
  210. is treating the directory routine as a subroutine and then JUMPING to the 
  211. error routine. Once we do that the RTS in read'err will return us back to basic.
  212.  
  213. .@042! ;;----------------------------------------------------------------------
  214. .@043!
  215. .@044! read'dir = *
  216. .@045! 
  217. .@046! ; Opens and reads directory as a basic program.
  218. .@047! ;==
  219. .@048! ; Basic programs are read in as follows:
  220. .@049! ;                  [Ptr to Next Line]:2 [Line #]:2 [Text]:.... [$00 byte]
  221. .@050! ;                  ^^^^^^^^^^^REPEATS^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  222. .@051! ; The end of a program is signifed by the $00 byte signifying end of text
  223. .@052! ;    and the ptr's also being = $00.
  224. .@053! ;==
  225.  
  226.   There are several ways to read the directory in machine language.  What we are
  227. doing here is taking advantage of the drive's ability to allow us to load the
  228. directory as a basic program -*except*- we aren't loading it per se. We're 
  229. gonna grab each byte as it comes from the drive and interpret it ourselves
  230. instead of putting it in memory as would normally be done.
  231.  
  232.   Basic programs are stored as the following: A 2 byte pointer, a 2 byte
  233. line #, the basic text, and a null terminator and then starting over
  234. from the 2 byte pointer.  The pointer we do not need, the line # is the number
  235. of blocks the file takes up and the TEXT is the program name and file type. We
  236. know when we're finished on the line by checking for a $00 byte.
  237.  
  238. .@054!                                ; Begin by opening up the 
  239. .@055!                                ; directory file ("$").
  240. .@056!        lda #$01                ;   length is 1        
  241. .@057!        ldx #<dir               ;   lo byte pointer to file name.
  242. .@058!        ldy #>dir               ;   hi byte pointer to file name.
  243. .@059!        jsr setnam              ; - call setnam
  244.  
  245.   Okay, first we need to simulate opening the directory as a program file.
  246. SETNAM sets up the filename for the open command.  In effect we are giving the 
  247. basic syntax of open file#,device#,channel#,"filename" in reverse.
  248.  
  249. .@060!        lda #$01                ;   file # 1
  250. .@061!        ldx #$08                ;   device # 8
  251. .@062!        ldy #$00                ;   channel # 0
  252. .@063!        jsr setlfs              ; - call setlfs
  253.  
  254.   Here we specify the device #, file #, channel # in preperation for the open.
  255.  
  256. .@064!        jsr open                ; - call open
  257.  
  258.   Open up the file. This is the routine that does the real work. SETNAM and
  259. SETLFS were preparatory routines for this.
  260.  
  261. .@065!  ;
  262. .@066!  ; read in the bytes and display (skipping line links etc)
  263. .@067!  ;
  264. .@068!        ldx #$01               ;   file #1
  265. .@069!        jsr chkin              ; - call chkin to set input file #.
  266.  
  267.   Now we need to specify the input file # and tell the computer that all further
  268. chrin's are to be from file #1. (By default, it would have read from the 
  269. keyboard unless we had this here).
  270.  
  271. .@070!        jsr chrin              ; - ignore starting address (2 bytes)
  272. .@071!        jsr chrin 
  273.  
  274.   Skip the starting address -- When reading the directory it is not relevant
  275. so read the bytes and discard them.
  276.  
  277. .@072!  skip  jsr chrin              ; - ignore pointer to next line (2 bytes)
  278.  
  279.   Now we skip the pointer for the next line. This is only used when loading
  280. basic programs to re-link the lines. When listing the directory they are not
  281. needed.
  282.  
  283. .@073!  bck1  jsr chrin
  284.  
  285.   This is still part of the routine that skips the pointer to the next line, yet
  286. it has a label used below that allows us to check for end of file more easily.
  287.  
  288. .@074!  line  jsr chrin              ; - get line # lo.
  289. .@075!        sta temp               ; - store lo of line # @ temp
  290. .@076!        jsr chrin              ; - get hi of line #
  291.  
  292.   Here we get the line # as the next 2 bytes in the file.
  293.  
  294. .@077! 
  295. .@078! .if computer-64               ; * if C128 then
  296.  
  297.   Unfortunately C= did not provide a nice routine in the KERNAL to display 
  298. numeric values - however - by exploring inside the operating system a way to 
  299. display numbers is there.  Note that the following may look confusing -- if it
  300. does just rest assured it will print out the line # correctly.
  301.   
  302. .@079!        sta $61
  303. .@080!        ldy temp
  304. .@081!        sty $60
  305. .@082!        lda #$00
  306. .@083!        sta $63
  307. .@084!        ldy temp                ;   store values for conversion.
  308. .@085!        jsr $ba07               ; - MONITOR routine: convert to BCD values
  309. .@086!        lda #$00
  310. .@087!        ldx #$08
  311. .@088!        ldy #$03
  312. .@089!        jsr $ba5d               ; - MONITOR routine: print BCD 
  313. .@090!                                ;values in decimal
  314.  
  315.   This is the C128 version which uses some of the MONITOR routines to display
  316. the numeric block size.
  317.  
  318. .@091! .else                          ; * else if c64
  319. .@092!        ldx temp 
  320. .@093!        jsr $bdcd               ; - print line # (w/in ROM routine).
  321. .@094! .ife                           ; * end of computer dependant code.
  322.  
  323.   This is the C64 code to display a numeric value (notice how much simplified it
  324. is over the C128)...
  325.  
  326. .@095!
  327. .@096!        lda #space
  328. .@097!        jsr bsout               ; - print space
  329.  
  330.   Let's print a space between the filename and the block size.
  331.  
  332. .@098!  gtasc jsr chrin               ; - start printing filename until 
  333. .@099!                                ;end of line.
  334. .@100!        beq chck                ;   (Zero signifies eol).
  335. .@101!        jsr bsout               ; - Print character
  336. .@102!        sec
  337. .@103!        bcs gtasc               ;   and jump back.
  338.  
  339.   Now we start getting a character (line #98), if zero we branch out of the loop
  340. (line #100), else we display the character (#101), and jump back (#102-03).
  341.  
  342. .@104!  chck  lda #charret            ; - Else we need to start the next line
  343. .@105!        jsr bsout               ;   Print a carriage return.
  344.  
  345.   Ah, we got to a null byte so that's the end of this line - display a car/ret.
  346.  
  347. .@106!        jsr chrin               ; - And get the next pointer
  348. .@107!        bne bck1                ;   If non-zero go, strip other ptr,
  349. .@108!                                ; and continue.
  350.  
  351.   This is where we branch back -- we are checking here for 2 null bytes on 
  352. input.  We get the first byte of the pointer and if it's non-zero then we know
  353. it's not the end of the directory so we jump back to discard the second byte at
  354. line #73.
  355.  
  356. .@109!        jsr chrin               ; - Else check 2nd byte of pointer
  357. .@110!        bne line                ;   as if both 0 then = end of directory.
  358.  
  359.   This is a continuation of the checking above. This time we're getting the 
  360. 2nd byte and checking for 0.  If it's not we jump back to get and display the
  361. line # etc. If it is 0 then that means we had $0000 for the next pointer which
  362. means that it's the end of the directory.
  363.  
  364. .@111!  ;
  365. .@112!  ;had 3 0's in a row so end of prog
  366. .@113!  ;now close the file.
  367. .@114!  ;
  368. .@115!        lda #$01                ;   file # to close
  369. .@116!        jsr close               ; - so close it
  370. .@117!        jsr clrch               ; - clear all channels
  371. .@118!        rts                     ; - and return to basic
  372. .@119!
  373.  
  374.   We then close the file by specifying the file # and calling close. We then 
  375. tell the computer to reset all the default input / output devices by calling
  376. clrch (remember we changed the default input channel??). And then we can return
  377. to where this routine was called from.
  378.  
  379. .@120! ; FILENAME string
  380. .@121! dir    .asc "$"
  381.  
  382.   This is the string that is pointed to by the SETNAM call. Note that a search
  383. pattern could be set by
  384.       line#121:       .asc "$hack*" 
  385. and by changing the length set in .A in the call in line #56.
  386.  
  387. .@122!
  388. .@123! ;;-----------------------------------------------------------------------
  389. .@124!
  390. .@125! read'err = *
  391. .@126! 
  392. .@127! ; This routine simply grabs bytes from a channel 15 it opens up until
  393. .@128! ;   a car/ret byte is found. Then it closes and returns.
  394. .@129! 
  395.  
  396.   Reading the error channel is much much more simpler than reading the 
  397. directory.  Basically we just open up the channel (specifying a null name) and
  398. repeatadly get bytes until a car/ret is found.
  399.  
  400. .@130! rderr  lda #$00                ;   length is 0
  401. .@131!        jsr setnam              ; - call setname
  402.  
  403.   Setup so we don't specify a name (length = 0).
  404.  
  405. .@132!        lda #$0f                ;   file # (15)
  406. .@133!        ldx #$08                ;   device # (08)
  407. .@134!        ldy #$0f                ;   channel # (15)
  408. .@135!        jsr setlfs              ; - set logical file #
  409.  
  410.   Do the equivlent of open 15,8,15.
  411.  
  412. .@136!        jsr open                ; - and open it.
  413.  
  414.   Open it.
  415.  
  416. .@137!  ;specify file as input
  417. .@138!        ldx #$0f                ;   file 15 is input
  418. .@139!        jsr chkin               ; - so specify it.
  419.  
  420.   Now set up file # 15 as input so we can start getting, displaying etc until
  421. a car/ret is found.
  422.  
  423. .@140!  ;now read in file
  424. .@141!  loop  jsr chrin               ; - read char
  425. .@142!        jsr bsout               ; - print char
  426. .@143!        cmp #charret            ;   is it return?
  427. .@144!        bne loop                ; - if not jmp back
  428.  
  429.   Read in and display the characters from the error channel until a char/ret is
  430. found.
  431.  
  432. .@145!  ;now close the file
  433. .@146!        lda #$0f                ;   file #
  434. .@147!        jsr close               ; - close the file
  435. .@148!        jsr clrch               ;   restore i/o
  436.  
  437.   And once it is, we close the file and restore the default i/o settings.
  438.  
  439. .@149!  ;now return to basic
  440. .@150!        rts
  441.  
  442.   And return to our caller, in this case - basic.
  443.  
  444. ============================================================================
  445. [ The Demo Corner is going to be a column where each month we'll be 
  446.   introduced to a new feature (some people call them bugs, we'll call them
  447.   features) of the Commodore 64 or 128 in the Video and Sound areas that 
  448.   have commonly been shown on demos but with no mention of how to accomplish
  449.   them. Note that readers may also want to take a look at the introduction
  450.   to Rasters elsewhere in this magazine.]
  451.  
  452. The Demo Corner: Missing Cycles
  453. by Pasi 'Albert' Ojala   (po87553@cs.tut.fi albert@cc.tut.fi)
  454.                           Written on  15-May-91  Translation 30-May-92
  455.  
  456.  
  457.                           Missing Cycles
  458.                           --------------
  459.        [all timings are in PAL, the principle applies to NTSC too]
  460.  
  461. Everybody knows that there are 63 cycles available to the C64 processor on
  462. each scan line, except for one which only provides 23 cycles (later referred
  463. to as a "bad" scan line). But what happens when we add sprites and why ?
  464.  
  465. In the C64, the VIC (video interface controller) has much more to do than
  466. just showing graphics on the screen. It also handles the memory refresh.
  467. On each scanline, it has to refresh five rows in the memory matrix and
  468. fetch fourty bytes of graphics data.
  469.  
  470. The VIC does all of this during the cycles (phase 1) that the processor is
  471. not using the memory.  These cycles, however, are not sufficient when the
  472. VIC also needs to access the character and color codes for the next row.
  473. The memory bus can't be used by the CPU and the VIC at the same time, so CPU
  474. access to the bus must be denied to allow the VIC to fetch its data.
  475. Fortunately, the VIC bus (12-bit wide) allows the character (8 bits) and
  476. color (4 bits) codes to be fetched at the same time.
  477.  
  478.  
  479. _Understanding how sprites work_
  480.  
  481. If there are sprites on the screen, the VIC needs even more cycles to fetch
  482. all of the graphics data. Scan lines are time divided so that there is
  483. enough time for all action during one line. On each line, the sprite
  484. image pointers are fetched during phase 1. If the sprite is to be displayed
  485. on that line, the three bytes of image data are fetched right after that.
  486. Out of these three fetches, two take place during phase 2 of the clock,
  487. so the processor will lose these. On average, two clock cycles are lost
  488. for each sprite that is displayed on that line.
  489.  
  490. But how is it possible for all eight sprites to only take 16-19 cycles
  491. (depending on the timing) when we have observed that one sprite requires
  492. three cycles? And why do sprites 0, 2, 4, 6 and 7 together take up as many
  493. cycles as all eight sprites ? The answer may be found in the way the VIC
  494. tells the CPU that it needs additional cycles.
  495.  
  496.  
  497. _The BA signal_
  498.  
  499. When the VIC wants to use the bus, the BA (Bus Available) signal goes
  500. inactive. This will happen three cycles before the bus must be released !
  501. During these three cycles, the CPU must complete all memory accesses or
  502. delay them until it has the bus again.
  503.  
  504. The CPU either completes the current instruction in the remaining cycles
  505. or sits and waits for the bus to become available again. It can't execute
  506. a new instruction as long as it doesn't have the bus. This is why cycles
  507. seem to be lost (besides those stolen directly for the sprites). Usually,
  508. all 8 sprites take 17 cycles while one sprite takes three cycles. However,
  509. the CPU may continue to execute an instruction if it does not use the bus.
  510.  
  511.  
  512. _Theory and speculation_
  513.  
  514. Let's suppose that all the sprites are enabled and on the same scan line.
  515. Then, the VIC steals 16 cycles (2 cycles for each sprite) for the memory
  516. fetches and 3 cycles as overhead for the BA signal, for a total of 19 cycles.
  517. However, it will be usually less because the CPU will use some of the cycles
  518. when the bus request is pending.
  519.  
  520. If we now disable sprite 4, no cycles are released for the CPU's use. This
  521. is because during the previous sprite 4 data fetch, the VIC already signals
  522. that it needs the bus for the sprite 5 data fetch and BA stays low (Refer
  523. to the timing chart). Thus, the CPU never sees BA go high during sprite 4
  524. and 2 cycles are still lost.
  525.  
  526. Accordingly, if we only turn off sprites 1, 3 and 5 we get no cycles back
  527. from the VIC. So in time-critical raster routines, always use sprites in
  528. order.
  529.  
  530.  
  531. _What can we do with this feature ?_
  532.  
  533. How can this be useful? A good use is for synchronization. Normally,
  534. before the CPU starts to execute the raster interrupt code, it's executing
  535. an instruction of undefined cycle-length. This execution time varies from
  536. two to seven cycles.
  537.  
  538. With a sprite, you can do the synchronization with a minimal effort using
  539. a DEC or INC instruction in the right place. If the processor is early,
  540. it has to wait for the bus, otherwise it will continue to execute cycles
  541. from the instruction.
  542.  
  543. I have never experimented with any other instruction than DEC/INC, but
  544. some others should work also. You need an instruction which has a cycle that
  545. do not need the bus to be available. e.g. INC $3fff will increase the
  546. value during the fifth cycle and do not need the bus for that.
  547.  
  548.  
  549. _A demo program_
  550.  
  551. The enclosed program includes a short raster color routine to demonstrate
  552. this strict timing and synchronization. The background color is changed
  553. 12 times on each line. The electron beam runs over eight pixels during
  554. one cycle, so the timing must be precise.
  555.  
  556. --------------------------------------------------------------------------
  557. _Table for PAL VIC timing for the Missing cycles_
  558.  
  559.  
  560. 012345678901234567890123456789012345678901234567890123456789012 cycles
  561.  
  562. Normal scan line, 0 sprites
  563. ggggggggggggggggggggggggggggggggggggggggrrrrr  p p p p p p p p  phi-1 VIC
  564.                                                                 phi-2 VIC
  565. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx phi-2 6510
  566. 63 cycles available
  567.  
  568. Normal scan line, 8 sprites
  569. ggggggggggggggggggggggggggggggggggggggggrrrrr  pspspspspspspsps phi-1 VIC
  570.                                                ssssssssssssssss phi-2 VIC
  571. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXX                 phi-2 6510
  572. 46-49 cycles available
  573.  
  574. Normal scan line, 4 sprites
  575. ggggggggggggggggggggggggggggggggggggggggrrrrr  psp psp psp psp  phi-1 VIC
  576.                                                ss  ss  ss  ss   phi-2 VIC
  577. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXX              xx phi-2 6510
  578. 48-51 cycles available
  579.  
  580. Bad scan line, 0 sprites
  581. ggggggggggggggggggggggggggggggggggggggggrrrrr  p p p p p p p p  phi-1 VIC
  582. cccccccccccccccccccccccccccccccccccccccc                        phi-2 VIC
  583.                                         xxxxxxxxxxxxxxxxxxxxxxx phi-2 6510
  584. 23 cycles available
  585.  
  586. Bad scan line, 8 sprites
  587. ggggggggggggggggggggggggggggggggggggggggrrrrr  pspspspspspspsps phi-1 VIC
  588. cccccccccccccccccccccccccccccccccccccccc       ssssssssssssssss phi-2 VIC
  589.                                         xxxxXXX                 phi-2 6510
  590. 4-7 cycles available
  591.  
  592.  
  593. g= grafix data fetch (character images or graphics data)
  594. r= refresh
  595. p= sprite image pointer fetch
  596. c= character and color CODE fetch during a bad scan line
  597. s= sprite data fetch
  598. x= processor executing instructions
  599. X= processor executing an instruction, bus request pending
  600.  
  601. Observe! The left edge of the chart is not the left edge of the screen nor
  602.      the left edge of the beam, but the sprite x-coordinate 0. If you
  603.      have opened the borders, you know what I mean. A sprite can be
  604.      moved left from the coordinate 0 by using x-values greater than 500.
  605.  ___________
  606. |  _______  |<-- Maximum sized video screen
  607. |||       | |
  608. |||       |<-- Normal C64 screen
  609. |||       | |
  610. |||_______| |
  611. ||          |
  612. ||__________|
  613.  ^ Sprite coordinate 0
  614.  
  615.  
  616. --------------------------------------------------------------------------
  617. Demonstration program for missing cycles
  618.  
  619.  
  620. COLOR0= $CE00  ; Place for color bar 0
  621. COLOR1= $CF00  ; Place for color bar 1
  622. RASTER= $FA    ; Line for the raster interrupt
  623. DUMMY= $CFFF   ; Timing variable
  624.  
  625. *= $C000
  626.         SEI             ; Disable interrupts
  627.         LDA #$7F        ; Disable timer interrupts
  628.         STA $DC0D
  629.         LDA #$01        ; Enable raster interrupts
  630.         STA $D01A
  631.         STA $D015       ; Enable Sprite 0
  632.         LDA #<IRQ       ; Init interrupt vector
  633.         STA $0314
  634.         LDA #>IRQ
  635.         STA $0315
  636.         LDA #$1B
  637.         STA $D011
  638.         LDA #RASTER     ; Set interrupt position (inc. 9th bit)
  639.         STA $D012
  640.         LDA #RASTER-20  ; Sprite will just reach the interrupt position
  641.         STA $D001       ;  when it is positioned 20 lines earlier
  642.  
  643.         LDX #51
  644.         LDY #0
  645.         STA $D017       ; No Y-enlargement
  646. LOOP0   LDA COL,X       ; Create color bars
  647.         PHA
  648.         AND #15
  649.         STA COLOR0,X
  650.         STA COLOR0+52,Y
  651.         STA COLOR0+104,X
  652.         STA COLOR0+156,Y
  653.         PLA
  654.         LSR
  655.         LSR
  656.         LSR
  657.         LSR
  658.         STA COLOR1,X
  659.         STA COLOR1+52,Y
  660.         STA COLOR1+104,X
  661.         STA COLOR1+156,Y
  662.         INY
  663.         DEX
  664.         BPL LOOP0
  665.         CLI             ; Enable interrupts
  666.         RTS             ; Return
  667.  
  668.  
  669. IRQ     NOP             ; Wait a bit
  670.         NOP
  671.         NOP
  672.         NOP
  673.         LDY #103        ; 104 lines of colors (some of them not visible)
  674.             ; Reduce for NTSC, 55 ?
  675.         INC DUMMY       ; Handles the synchronization with the help of the
  676.         DEC DUMMY       ;  sprite and the 6-clock instructions
  677.             ; Add a NOP for NTSC
  678.  
  679. FIRST   LDX COLOR0,Y    ; Do the color effects
  680. SECOND  LDA COLOR1,Y
  681.         STA $D020
  682.         STX $D020
  683.         STA $D020
  684.         STX $D020
  685.         STA $D020
  686.         STX $D020
  687.         STA $D020
  688.         STX $D020
  689.         STA $D020
  690.         STX $D020
  691.         STA $D020
  692.         STX $D020
  693.             ; Add a NOP for NTSC (one line = 65 cycles)
  694.         LDA #0          ; Throw away 2 cycles (total loop = 63 cycles)
  695.         DEY
  696.         BPL FIRST       ; Loop for 104 lines
  697.  
  698.         STA $D020
  699.         LDA #103        ; For subtraction
  700.         DEC FIRST+1     ; Move the bars
  701.         BPL OVER
  702.         STA FIRST+1
  703. OVER    SEC
  704.         SBC FIRST+1
  705.         STA SECOND+1
  706.  
  707.         LDA #1          ; Ack the raster interrupt
  708.         STA $D019
  709.         JMP $EA31       ; Jump to the standard irq handler
  710.  
  711. COL     BYT $09,$90,$09,$9B,$00,$99,$2B,$08,$90,$29,$8B,$08,$9C,$20,$89,$AB
  712.         BYT $08,$9C,$2F,$80,$A9,$FB,$08,$9C,$2F,$87,$A0,$F9,$7B,$18,$0C,$6F
  713.         BYT $07,$61,$40,$09,$6B,$48,$EC,$0F,$67,$41,$E1,$30,$09,$6B,$48,$EC
  714.         BYT $3F,$77,$11,$11
  715.                         ; Two color bars
  716.  
  717. --------------------------------------------------------------------------
  718. Basic loader for Missing cycles example program (PAL)
  719.  
  720. 1 S=49152
  721. 2 DEFFNH(C)=C-48+7*(C>64)
  722. 3 CH=0:READA$,A:PRINTA$:IFA$="END"THENPRINT"<clr>":SYS49152:END
  723. 4 FORF=0TO31:Q=FNH(ASC(MID$(A$,F*2+1)))*16+FNH(ASC(MID$(A$,F*2+2)))
  724. 5 CH=CH+Q:POKES,Q:S=S+1:NEXT:IFCH=ATHEN3
  725. 6 PRINT"CHECKSUM ERROR":END
  726. 100 DATA 78A97F8D0DDCA9018D1AD08D15D0A9578D1403A9C08D1503A91B8D11D0A9FA8D, 3773
  727. 101 DATA 12D0A9E68D01D0A233A0008D17D0BDACC048290F9D00CE9934CE9D68CE999CCE, 4157
  728. 102 DATA 684A4A4A4A9D00CF9934CF9D68CF999CCFC8CA10D95860EAEAEAEAA067EEFFCF, 4878
  729. 103 DATA CEFFCFBE18CEB94FCF8D20D08E20D08D20D08E20D08D20D08E20D08D20D08E20, 4403
  730. 104 DATA D08D20D08E20D08D20D08E20D0A9008810D18D20D0A967CE64C010038D64C038, 3923
  731. 105 DATA ED64C08D67C0EE19D04C31EA0990099B00992B0890298B089C2089AB089C2F80, 3483
  732. 106 DATA A9FB089C2F87A0F97B180C6F076140096B48EC0F6741E130096B48EC3F771111, 3133
  733. 200 DATA END,0
  734.  
  735. --------------------------------------------------------------------------
  736. Uuencoded C64 executable version (PAL)
  737.  
  738. begin 644 missing.64
  739. M`0@-"`$`4[(T.3$U,@`F"`(`EJ5(*$,ILD.K-#BJ-ZPH0[$V-"D`40@#`$-(?
  740. MLC`ZAT$D+$$ZF4$D.HM!)+(B14Y$(J>9(I,B.IXT.3$U,CJ``(@(!`"!1K(P/
  741. MI#,Q.E&RI4@HQBC**$$D+$:L,JHQ*2DIK#$VJJ5(*,8HRBA!)"Q&K#*J,BDI:
  742. M*0"I"`4`0TBR0TBJ43J74RQ1.E.R4ZHQ.H(ZBT-(LD&G,P#!"`8`F2)#2$5#F
  743. M2U-532!%4E)/4B(Z@``."60`@R`W.$$Y-T8X1#!$1$-!.3`Q.$0Q040P.$0QK
  744. M-40P03DU-SA$,30P,T$Y0S`X1#$U,#-!.3%".$0Q,40P03E&03A$+"`S-S<SA
  745. M`%L)90"#(#$R1#!!.44V.$0P,40P03(S,T$P,#`X1#$W1#!"1$%#0S`T.#(Y?
  746. M,$8Y1#`P0T4Y.3,T0T4Y1#8X0T4Y.3E#0T4L(#0Q-3<`J`EF`(,@-C@T031!4
  747. M-$$T03E$,#!#1CDY,S1#1CE$-CA#1CDY.4-#1D,X0T$Q,$0Y-3@V,$5!14%%>
  748. M045!03`V-T5%1D9#1BP@-#@W.`#U"6<`@R!#149&0T9"13$X0T5".31&0T8X^
  749. M1#(P1#`X13(P1#`X1#(P1#`X13(P1#`X1#(P1#`X13(P1#`X1#(P1#`X13(PH
  750. M+"`T-#`S`$(*:`"#($0P.$0R,$0P.$4R,$0P.$0R,$0P.$4R,$0P03DP,#@XV
  751. M,3!$,3A$,C!$,$$Y-C=#138T0S`Q,#`S.$0V-$,P,S@L(#,Y,C,`CPII`(,@^
  752. M140V-$,P.$0V-T,P144Q.40P-$,S,45!,#DY,#`Y.4(P,#DY,D(P.#DP,CDX[
  753. M0C`X.4,R,#@Y04(P.#E#,D8X,"P@,S0X,P#<"FH`@R!!.49",#@Y0S)&.#=!?
  754. M,$8Y-T(Q.#!#-D8P-S8Q-#`P.39"-#A%0S!&-C<T,44Q,S`P.39"-#A%0S-&V
  755. ;-S<Q,3$Q+"`S,3,S`.@*R`"#($5.1"PP````8
  756. ``
  757. end
  758. size 747
  759.  
  760. --------------------------------------------------------------------------
  761. Uuencoded C64 executable version (NTSC)
  762.  
  763. begin 644 missing.64
  764. M`0@-"`$`4[(T.3$U,@`F"`(`EJ5(*$,ILD.K-#BJ-ZPH0[$V-"D`40@#`$-(?
  765. MLC`ZAT$D+$$ZF4$D.HM!)+(B14Y$(J>9(I,B.IXT.3$U,CJ``(@(!`"!1K(P/
  766. MI#,Q.E&RI4@HQBC**$$D+$:L,JHQ*2DIK#$VJJ5(*,8HRBA!)"Q&K#*J,BDI:
  767. M*0"I"`4`0TBR0TBJ43J74RQ1.E.R4ZHQ.H(ZBT-(LD&G,P#!"`8`F2)#2$5#F
  768. M2U-532!%4E)/4B(Z@``."60`@R`W.$$Y-T8X1#!$1$-!.3`Q.$0Q040P.$0QK
  769. M-40P03DU-SA$,30P,T$Y0S`X1#$U,#-!.3%".$0Q,40P03E&03A$+"`S-S<SA
  770. M`%L)90"#(#$R1#!!.44V.$0P,40P03(S,T$P,#`X1#$W1#!"1$%%0S`T.#(YA
  771. M,$8Y1#`P0T4Y.3,T0T4Y1#8X0T4Y.3E#0T4L(#0Q-3D`J`EF`(,@-C@T031!6
  772. M-$$T03E$,#!#1CDY,S1#1CE$-CA#1CDY.4-#1D,X0T$Q,$0Y-3@V,$5!14%%>
  773. M045!03`S-T5%1D9#1BP@-#@S,`#U"6<`@R!#149&0T9%04)%,#!#14(Y,#!#4
  774. M1CA$,C!$,#A%,C!$,#A$,C!$,#A%,C!$,#A$,C!$,#A%,C!$,#A$,C!$,#A%$
  775. M+"`T-3`R`$(*:`"#(#(P1#`X1#(P1#`X13(P1#`X1#(P1#`X13(P1#!%04$Y.
  776. M,#`X.#$P1#`X1#(P1#!!.38W0T4V-4,P,3`P,SA$-C4L(#,Y-#(`CPII`(,@R
  777. M0S`S.$5$-C5#,#A$-CA#,$5%,3E$,#1#,S%%03`Y.3`P.3E",#`Y.3)",#@Y(
  778. M,#(Y.$(P.#E#,C`X.4%",#@Y0RP@,S4U.`#<"FH`@R`R1C@P03E&0C`X.4,R_
  779. M1C@W03!&.3=",3@P0S9&,#<V,30P,#DV0C0X14,P1C8W-#%%,3,P,#DV0C0XK
  780. M14,S1C<W+"`S,C<T`"<+:P"#(#$Q,3$P,#`P,#`P,#`P,#`P,#`P,#`P,#`PO
  781. M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`L(#,T`#,+1
  782. ,;`"#($5.1"PP````"
  783. ``
  784. end
  785. size 822
  786.  
  787. ============================================================================
  788. Kernal 64 / 128 
  789. by Craig Taylor (duck@pembvax1.pembroke.edu)
  790.  
  791.                              +--------------+
  792.                              | Introduction |
  793.                              +--------------+
  794.  
  795.   When Commodore introduced the PET ages ago before the Vic-20 and Commodore 64,
  796. 128 they set in the highest memory locations a series of jumps to other routines
  797. so that users didn't need bother checking if any revisions had been made. They
  798. were assured that the address they were jumping to, would indeed, be the address
  799. that would print out a character or whatnot.
  800.  
  801.   The KERNAL has grown since Commodore first introduced it, the C=128 KERNAL has
  802. fifty-seven seperate routines which are available to programmers. These routines
  803. handle functions relating to the serial devices (the bulk of them), the screen
  804. and miscellanous system routines such as scanning the keyboard, updating and
  805. reading the system clock (TI$).
  806.  
  807.                           +-------------------+
  808.                           | Table of Routines |
  809.                           +-------------------+
  810.  
  811.   The following table lists the available routines, their function, address,
  812. their name, and registers affected upon exit. In addation, on the left of each
  813. line are the group that I have catagorized them under: Video(Vid), System(Sys),
  814. and Serial(Ser).
  815.  
  816. --------+---------+---------+---------------------------------------+-----------
  817.         |         |Registers|                                       |Group
  818. Address | NAME    | A X Y F | Descritption                          |Vid Sys Ser
  819. --------+---------+---------+---------------------------------------+-----------
  820. FF47/128|SPINSPOUT| *       | Initializes I/O for fast serial       |        ***
  821. FF4A/128| CLOSEALL| * * *   | Close all files on a device           |        ***
  822. FF4D/128| C64MODE |         | Switches to C=64 mode                 |    *** 
  823. FF50/128| DMACALL | * *     | Send DMA command to REU               |    ***
  824. FF53/128| BOOTCALL| * *   * | Attempts to run boot sector           |    *** ***
  825. FF56/128| PHOENIX | * * *   | Initalizes external/internal cartri.  |    ***
  826. FF59/128| LKUPLA  | * * * * | Looks up logical device #             |    *** ***
  827. FF5C/128| LKUPSA  | * * * * | Looks up for secondary address        |    *** ***
  828. FF5F/128| SWAPPER | * * *   | Switches betten 40 / 80 column screen |*** 
  829. FF62/128| DLCHAR  | * * *   | Initializes 80 column character set   |***
  830. FF65/128| PFKEY   | * * * * | Installs a function key definition    |    ***
  831. FF68/128| SETBNK  |         | Sets bank for any I/O operations      |    *** ***
  832. FF6B/128| GETCFG  | *       | Get MMU configuration for a given bank|    ***
  833. FF6E/128| JSRFAR  |         | Jumps to a subroutine in another bank |    ***
  834. FF71/128| JMPFAR  |         | Starts executing code in another bank |    ***
  835. FF74/128| INDFET  | * *   * | Execute a LDA(fetvec),Y from a bank   |    ***
  836. FF77/128| INDSTA  |   *   * | Stores a value indirectly in a bank   |    ***
  837. FF7A/128| INDCMP  |   *   * | Compares a value indirectly in a bank |    ***
  838. FF7D/128| PRIMM   |         | Outputs null-terminated string        |***     ***
  839. ////////|/////////|/////////|///////////////////////////////////////|///////////
  840. FF81    | CINT    | * * *   | Setup VIC,screen values, 8563...      |*** 
  841. FF84    | IOINIT  | * * *   | Initialize VIC,SID,8563,CIA for system|*** ***
  842. FF87    | RAMTAS  | * * *   | Initialize ram.                       |    ***
  843. FF8D    | VECTOR  | *   *   | Reads or Writes to Kernal RAM Vectors |    ***
  844. FF90    | SETMSG  |         | Sets Kernal Messages On/Off.          |    ***
  845. FF93    | SECND   | *       | Sends secondary address after LISTN   |    *** ***
  846. FF96    | TKSA    | *       | Sends secondary address after TALK    |    *** ***
  847. FF99    | MEMTOP  |   * *   | Read or set the top of system RAM.    |    ***
  848. FF9C    | MEMBOT  |   * *   | Read or set the bottom of system RAM. |    ***
  849. FF9F    | KEY     |         | Scans Keyboard                        |    ***
  850. FFA2    | SETMO   |         | -- Unimplemented Subroutine in All -- |   [N/A]
  851. FFA5    | ACPTR   | *       | Grabs byte from current talker        |    *** ***
  852. FFA8    | CIOUT   | *       | Output byte to current listener       |    *** ***
  853. FFAB    | UNTLK   | *       | Commands device to stop talking       |    *** ***
  854. FFAE    | UNLSN   | *       | Commands device to stop listening     |    *** ***
  855. FFB1    | LISTN   | *       | Commands device to begin listening    |    *** ***
  856. FFB4    | TALK    | *       | Commands device to begin talking      |    *** ***
  857. FFB7    | READSS  | *       | Returns I/O status byte               |        ***
  858. FFBA    | SETLFS  |         | Sets logical #, device #, secondary # |        ***
  859. FFBD    | SETNAM  |         | Sets pointer to filename.             |        ***
  860. FFC0    | OPEN    | * * * * | Opens up a logical file.              |        ***
  861. FFC3    | CLOSE   | * * * * | Closes a logical file.                |        ***
  862. FFC6    | CHKIN   | * * * * | Set input channel                     |        ***
  863. FFC9    | CHKOUT  | * * * * | Set output channel                    |        ***
  864. FFCC    | CLRCH   | * *     | Restore default channels              |        ***
  865. FFCF    | BASIN   | *     * | Input from channel                    |        ***
  866. FFD2    | BSOUT   | *     * | Output to channel (aka CHROUT)        |***     ***
  867. FFD5    | LOAD    | * * * * | Load data from file                   |        ***
  868. FFD8    | SAVE    | * * * * | Save data to file                     |        ***
  869. FFDB    | SETTIM  |         | Sets internal (TI$) clock             |    *** 
  870. FFDE    | RDTIM   | * * *   | Reads internal (TI$) clock            |    ***
  871. FFE1    | STOP    | * *     | Scans and check for STOP key          |    ***
  872. FFE4    | GETIN   | * * * * | Reads buffered data from file         |        ***
  873. FFE7    | CLALL   | * *     | Close all open files and channels     |        ***
  874. FFEA    | UDTIM   | * *     | Updates internal (TI$) clock          |    ***
  875. FFED    | SCRORG  | * * *   | Returns current window/screen size    |*** 
  876. FFF0    | PLOT    |   * * * | Read or set cursor position           |***
  877. FFF3    | IOBASE  |   * *   | Read base of I/O block                |    ***
  878. --------+---------+---------+---------------------------------------+-----------
  879.  
  880.                           
  881.                           +--------------------------+
  882.                           | The Routines Themselves. |
  883.                           +--------------------------+
  884.  
  885. A. Error handling
  886.  
  887.   For the routines in the KERNAL that return status codes (indicated by the FL
  888. status in the chart) the carry is set if there is an error.  Otherwise, the 
  889. carry returned is clear.  If the carry is set, the error code is returned in the
  890. accumalator:
  891.                                            +-----------------------------------+
  892.        .A |Meaning                         | NOTE: Some of the I/O routines    |
  893.       ----+------------------------------  |       indicate the error code via |
  894.         0 | Stop Key pressed               |       the READST routine when     |
  895.         1 | Too Many Open Files            |       setting the carry.          |
  896.         2 | File Already Open              +------------------------------------
  897.         3 | File Not Open
  898.         4 | File Not Found
  899.         5 | Device Not Present
  900.         6 | File Was Not Opened As Input
  901.         7 | File Was Not Opened As Output
  902.         8 | File Name Not Present
  903.         9 | Illegal Device Number
  904.        41 | File Read Error
  905.  
  906.  
  907. B. Device Numbers:
  908.  
  909.   The following table lists the "standard" device numbers used by the C= Kernal.
  910.  
  911.            +---------+----------------------------+
  912.            |Device # | Device Name                |
  913.            +---------+----------------------------+
  914.            |   0     | Keyboard (standard input)  |
  915.            |   1     | Cassette                   |
  916.            |   2     | RS-232                     |
  917.            |   3     | Screen   (standard output) |
  918.            |   4 - 30| Serial Bus Devices         |
  919.            |     4-7 | Printers        (typically)|
  920.            |     8-30| Disk Drives     (typically)|
  921.            +---------+----------------------------+
  922.  
  923. C. Routine Descriptions.
  924.  
  925.   Due to space limitations a fully-detailed, descriptive summary of the KERNAL
  926. routines is not feasible.  However, listed below is a description of what each
  927. routine does, expected parameters and any notes on C=128/C=64 differences as 
  928. well as notes to clarify any possibly confusing details.
  929.  
  930.  ---------------------------------------------------------------------------
  931.  
  932. Routine        : SPINSPOUT ** 128 ONLY **
  933.  Kernal Address: $FF47
  934.  Description   : Setup CIA for BURT protocol.
  935.  Registers In  : .C = 0 -> SPINP (input)
  936.                  .C = 1 -> SPOUT (output)
  937.  Registers Out : .A destroyed
  938.  Memory Changed: CIA, MMU.
  939.  
  940. Routine        : CLOSEALL ** 128 ONLY **
  941.  Kernal Address: $FF4A
  942.  Description   : Close all files on a device.
  943.  Registers In  : .A = device # (0-31)
  944.  Registers Out : .A, .X, .Y used.
  945.  Memory Changed: None.
  946.  
  947. Routine        : C64MODE ** 128 ONLY **
  948.  Kernal Address: $FF4D
  949.  Description   : Switches to C64 Mode
  950.  Registers In  : None.
  951.  Registers Out : None.
  952.  Memory Changed: -ALL- This routine initializes and calls the C64 cold start
  953.                  routine. There is no way to switch out of C64 mode once this
  954.                  routine is entered.
  955.  
  956. Routine        : DMACALL ** 128 ONLY **
  957.  Kernal Address: $FF50
  958.  Description   : Perform DMA command (for REU)
  959.  Registers In  : .X = Bank, .Y = DMA controller command
  960.                  NOTE: REU registers must have been previously setup.
  961.  Registers Out : .A, .X used
  962.  Memory Changed: Dependenant upon REU registers, REU command.
  963.  
  964. Routine        : BOOTCALL ** 128 ONLY **
  965.  Kernal Address: $FF53
  966.  Description   : Attempts to load and execute boot sector from a drive.
  967.  Registers In  : .A = drive # in ascii (usually '0' / $30)
  968.                  .X = device #
  969.  Registers Out : .A, .X, .Y used. .C = 1 if I/O error.
  970.  Memory Changed: As per boot sector. 
  971.  
  972. Routine        : PHOENIX ** 128 ONLY **
  973.  Kernal Address: $FF56
  974.  Description   : Initalizes external / internatal cartridges,check for disk boot
  975.  Registers In  : None.
  976.  Registers Out : .A, .X, .Y used.
  977.  Memory Changed: Calls any auto-start catridges that are installed on the system
  978.  
  979. Routine        : LKUPLA ** 128 ONLY **
  980.  Kernal Address: $FF59
  981.  Description   : Search file tables for a given logical device #.
  982.  Registers In  : .A = Logical Device #.
  983.  Registers Out : .C = 0 if found -> .A = Logical Device #, 
  984.                                     .X = Logical File #,
  985.                                     .Y = Logical Secondary #.
  986.                  .C =1 if not found.
  987.  Memory Changed: None.
  988.  
  989. Routine        : LKUPSA ** 128 ONLY **
  990.  Kernal Address: $FF5C
  991.  Description   : Search file tables for a given secondary address.
  992.  Registers In  : .Y = Secondary address to search for.
  993.  Registers Out : As LKUPLA (see LKUPLA).
  994.  Memory Changed: None.
  995.  
  996. Routine        : SWAPPER ** 128 ONLY **
  997.  Kernal Address: $FF5F
  998.  Description   : Switches between 40 / 80 column screen.
  999.  Registers In  : None.
  1000.  Registers Out : .A, .X, .Y destroyed.
  1001.  Memory Changed: Screen Editor Locations.
  1002.  
  1003. Routine        : DLCHAR ** 128 ONLY **
  1004.  Kernal Address: $FF62
  1005.  Description   : Initializes 80 column character set.
  1006.  Registers In  : None.
  1007.  Registers Out : .A, .X, .Y destroyed.
  1008.  Memory Changed: None.
  1009.  
  1010. Routine        : PFKEY ** 128 ONLY **
  1011.  Kernal Address: $FF65
  1012.  Description   : Installs a function key definition      
  1013.  Registers In  : .A = pointer to Z-P address (3 bytes : address lo/hi/bank.)
  1014.                  .Y = length, .X = key # (9 = Shift RUN/STOP, 10 = HELP).
  1015.  Registers Out : .C = 1 if No room, .C = 0 if successful.
  1016.                  .A, .X, .Y destroyed.
  1017.  Memory Changed: Function Key Table modified.
  1018.  
  1019. Routine        : SETBNK ** 128 ONLY **
  1020.  Kernal Address: $FF68
  1021.  Description   : Sets bank for any future I/O operations
  1022.  Registers In  : .A = Memory Bank, .X = Bank where filename is.
  1023.  Registers Out : None.
  1024.  Memory Changed: None.
  1025.  
  1026. Routine        : GETCFG ** 128 ONLY **
  1027.  Kernal Address: $FF6B
  1028.  Description   : Get MMU configuration for a given bank.
  1029.  Registers In  : None.
  1030.  Registers Out : None.
  1031.  Memory Changed: 
  1032.  
  1033. Routine        : JSRFAR ** 128 ONLY **
  1034.  Kernal Address: $FF6E
  1035.  Description   : Jumps to a subroutine in another bank.
  1036.  Registers In  : None. (See JMPFAR for mem locations IN)
  1037.  Registers Out : None. (See JMPFAR for mem locations OUT)
  1038.  
  1039. Routine        : JMPFAR ** 128 ONLY **
  1040.  Kernal Address: $FF71
  1041.  Description   : Starts executing code in another bank.  
  1042.  Registers In  : None.
  1043.    Memory In   :  $02 - Bank (0-15)
  1044.                   $03 - PC high
  1045.                   $04 - PC lo
  1046.                   $05 - .S (Processor status)
  1047.                   $06 - .A
  1048.                   $07 - .X
  1049.                   $08 - .Y
  1050.  Registers Out : None.
  1051.    Memory Out  : As memory in.
  1052.  
  1053. Routine        : INDFET ** 128 ONLY **
  1054.  Kernal Address: $FF74
  1055.  Description   : Execute a LDA(fetvec),Y from a bank.
  1056.  Registers In  : .A - pointer to Z-Page location holding address
  1057.                  .X - Bank (0-15), .Y - Index.
  1058.  Registers Out : .A = data, .X - destroyed.
  1059.  Memory Changed: None.
  1060.  
  1061. Routine        : INDSTA ** 128 ONLY **
  1062.  Kernal Address: $FF77
  1063.  Description   : Execute a STA(stavec),Y in a bank.
  1064.  Registers In  : .A - pointer to Z-Page location holding address
  1065.                  .X - Bank (0-15), .Y - Index.
  1066.  Registers Out : .X - Destroyed.
  1067.  Memory Changed: As per registers.
  1068.  
  1069. Routine        : INDCMP ** 128 ONLY **
  1070.  Kernal Address: $FF7A
  1071.  Description   : Executes a CMP(cmpvec),Y in a bank.
  1072.  Registers In  : .A = data, .X = Bank (0-15), .Y - Z-Page ptr.
  1073.  Registers Out : .X destroyed, Flags set accordingly.
  1074.  Memory Changed: None.
  1075.  
  1076. Routine        : PRIMM ** 128 ONLY **
  1077.  Kernal Address: $FF7D
  1078.  Description   : Prints null terminated string following JSR to current channel
  1079.  Registers In  : None.
  1080.  Registers Out : None.
  1081.  Memory Changed: Dependent upon current device. 
  1082.  Example       :
  1083.                [ . . . ]
  1084.                  JSR $FF7D         ; JSR to primm, / print following string.
  1085.                  .ASC "Hi World!"  ; String to print.
  1086.                  .BYT $00          ; IMPORTANT: Null Terminated.
  1087.                [ . . . ]
  1088.  
  1089.  ---------------------------------------------------------------------------
  1090.  
  1091. Routine        : CINT
  1092.  Kernal Address: $FF81
  1093.  Description   : Setup VIC, screen values, (128: 8563)...
  1094.  Registers In  : None.
  1095.  Registers Out : None.
  1096.  Memory Changed: Screen Editor Locations.
  1097.  
  1098. Routine        : IOINIT
  1099.  Kernal Address: $FF84
  1100.  Description   : Initializes pertinant display and i/o devices
  1101.  Registers In  : C64: None. | C128: $0A04/bit 7
  1102.                             |          0 - Full Setup.
  1103.                             |          1 - Partial Setup. (no 8563 char)
  1104.  Registers Out : .A, .X, .Y destroyed.
  1105.  Memory Changed: CIA's, VIC, 8502 port, (C128: also optionally 8563).
  1106.  Note          : This routine automatically distinguishes a PAL system from a
  1107.                  NTSC system and sets PALCNT accordingly for use in the 
  1108.                  time routines.
  1109.  
  1110. Routine        : RAMTAS
  1111.  Kernal Address: $FF87
  1112.  Description   : Clears Z-Page, Sets RS-232 buffers, top/bot Ram.
  1113.  Registers In  : None.
  1114.  Registers Out : .A, .X, .Y destroyed.
  1115.  Memory Changed: Z-Page, Rs-232 buffers, top/bot Ram ptrs
  1116.  
  1117. Routine        : VECTOR
  1118.  Kernal Address: $FF8D
  1119.  Description   : Copies / Stores KERNAL indirect RAM vectors.
  1120.  Registers In  : .C = 0 (Set KERNAL Vectors) | .C = 1 (Duplicate KERNAL vectors)
  1121.                  .XY = address of vectors    | .XY = address of user vectors
  1122.  Registers Out : .A, .Y destroyed            | .A, .Y destroyed.
  1123.  Memory Changed: KERNAL Vectors changed      | Vectors written to .XY
  1124.  Note          : This routine is rarely used, usually the vectors are directly
  1125.                  changed themselves. The vectors, in order, are :
  1126.  
  1127.                  C128: IRQ,BRK,NMI,OPEN,CLOSE,CHKIN,CHKOUT,CLRCH,BASIN,BSOUT
  1128.                        STOP,GETIN,CLALL,EXMON (monitor),LOAD,SAVE
  1129.                  C64 : IRQ,BRK,NMI,OPEN,CLOSE,CHKIN,CHKOUT,CLRCH,BASIN,BSOUT
  1130.                        STOP,GETIN,CLALL,USRCMD (not used),LOAD,SAVE
  1131.  
  1132. Routine        : SETMSG
  1133.  Kernal Address: $FF90
  1134.  Description   : Set control of KERNAL control and error messages.
  1135.  Registers In  : .A bit 7 = KERNAL Control Messages (1 = on)
  1136.                     bit 6 = KERNAL Error   Messages (1 = on)
  1137.  Registers Out : None.
  1138.  Note          : KERNAL Control messages are those defined as Loading, Found etc
  1139.                  ... KERNAL Error messages are I/O ERROR # messages which are
  1140.                  listed as follows:
  1141.  
  1142. Routine        : SECND
  1143.  Kernal Address: $FF93
  1144.  Description   : Sends secondary address to device after a LISTN
  1145.  Registers In  : .A = secondary address
  1146.  Registers Out : .A used.
  1147.  Memory Changed: None.
  1148.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1149.  
  1150. Routine        : TKSA
  1151.  Kernal Address: $FF96
  1152.  Description   : Sends secondary address to device after TALK
  1153.  Registers In  : .A = secondary address.
  1154.  Registers Out : .A used.
  1155.  Memory Changed: None.
  1156.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1157.  
  1158. Routine        : MEMTOP
  1159.  Kernal Address: $FF99
  1160.  Description   : Read or Set top of System Ram
  1161.  Registers In  : .C = 1 (Read MemTop)     | .C = 0 (Set MemTop)
  1162.                                           | .XY = top of memory
  1163.  Registers Out : .XY = top of memory      | None.
  1164.  Memory Changed: None.                    | Top of memory changed.
  1165.  Note          : On the C=128, this routine refers to the top of BANK 0 RAM, not
  1166.                  BANK 1 RAM.
  1167.  
  1168. Routine        : MEMBOT
  1169.  Kernal Address: $FF9C
  1170.  Description   : Read or Set bottom of System Ram
  1171.  Registers In  : .C = 1 (Read MemBot)     | .C = 0 (Set MemBot)
  1172.                                           | .XY = bottom of memory.
  1173.  Registers Out : .XY = bottom of memory   | None.
  1174.  Memory Changed: None.                    | Bottom of Memory changed.
  1175.  Note          : On the C=128, this routine refers to the bottom of BANK 0 RAM, 
  1176.                  not, BANK 1 RAM.
  1177.  
  1178. Routine        : KEY
  1179.  Kernal Address: $FF9F
  1180.  Description   : Scans Keyboard
  1181.  Registers In  : None.
  1182.  Registers Out : None.
  1183.  Memory Changed: Relevant System Keyboard Values
  1184.  
  1185. Routine        : SETMO
  1186.  Kernal Address: $FFA2
  1187.  Description   : This is a routine who's code never made it into any versions
  1188.                  of the KERNAL on the C64, Vic-20 and C128.  Thus it is of no
  1189.                  pratical use.
  1190.  
  1191. Routine        : ACPTR
  1192.  Kernal Address: $FFA5
  1193.  Description   : Get byte from current talker.
  1194.  Registers In  : None.
  1195.  Registers Out : .A = data byte.
  1196.  Memory Changed: None.
  1197.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1198.  
  1199. Routine        : CIOUT
  1200.  Kernal Address: $FFA8
  1201.  Description   : Output byte to current listener.
  1202.  Registers In  : .A = byte.
  1203.  Registers Out : .A used.
  1204.  Memory Changed: None.
  1205.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1206.  
  1207. Routine        : UNTLK
  1208.  Kernal Address: $FFAB
  1209.  Description   : Commands current TALK device to stop TALKING.
  1210.  Registers In  : None.
  1211.  Registers Out : .A used.
  1212.  Memory Changed: None.
  1213.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1214.  
  1215. Routine        : UNLSN
  1216.  Kernal Address: $FFAE
  1217.  Description   : Commands current listening device to stop listening.
  1218.  Registers In  : None.
  1219.  Registers Out : .A used.
  1220.  Memory Changed: None.
  1221.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1222.  
  1223. Routine        : LISTN
  1224.  Kernal Address: $FFB1
  1225.  Description   : Commands device to begin listening.
  1226.  Registers In  : .A = device #.
  1227.  Registers Out : .A used.
  1228.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1229.  
  1230. Routine        : TALK
  1231.  Kernal Address: $FFB4
  1232.  Description   : Commands device to begin talking.
  1233.  Registers In  : .A = device #.
  1234.  Registers Out : .A used.
  1235.  Memory Changed: None.
  1236.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1237.  
  1238. Routine        : READSS
  1239.  Kernal Address: $FFB7
  1240.  Description   : Return I/O status byte.
  1241.  Registers In  : None.
  1242.  Registers Out : .A = status byte. (see section on ERROR messages).
  1243.  Memory Changed: None.
  1244.  
  1245. Routine        : SETLFS
  1246.  Kernal Address: $FFBA
  1247.  Description   : Set logical file #, device #, secondary # for I/O.
  1248.  Registers In  : .A = logical file #, .X = device #, .Y = secondary #
  1249.  Registers Out : None.
  1250.  Memory Changed: None.
  1251.  
  1252. Routine        : SETNAM
  1253.  Kernal Address: $FFBD
  1254.  Description   : Sets pointer to filename in preperation for OPEN.
  1255.  Registers In  : .A = string length, .XY = string address.
  1256.  Registers Out : None.
  1257.  Memory Changed: None.
  1258.  Note          : To specify _no_ filename specify a length of 0.
  1259.  
  1260. Routine        : OPEN
  1261.  Kernal Address: $FFC0
  1262.  Description   : Open up file that has been setup by SETNAM,SETLFS
  1263.  Registers In  : None.
  1264.  Registers Out : .A = error code, .X,.Y destroyed.
  1265.                  .C = 1 if error.
  1266.  Memory Changed: None.
  1267.  
  1268. Routine        : CLOSE
  1269.  Kernal Address: $FFC3
  1270.  Description   : Close a logical file.
  1271.  Registers In  : .A = logical file #.
  1272.  Registers Out : .A = error code, .X,.Y destroyed.
  1273.                  .C = 1 if error
  1274.  Memory Changed: None.
  1275.  
  1276. Routine        : CHKIN
  1277.  Kernal Address: $FFC6
  1278.  Description   : Sets input channel.
  1279.  Registers In  : .X = logical file #.
  1280.  Registers Out : .A = error code, .X,.Y destroyed.
  1281.                  .C = 1 if error
  1282.  Memory Changed: None.
  1283.  
  1284. Routine        : CHKOUT
  1285.  Kernal Address: $FFC9
  1286.  Description   : Sets output channel.
  1287.  Registers In  : .X = logical file #.
  1288.  Registers Out : .A = error code, .X,.Y destroyed.
  1289.                  .C = 1 if error
  1290.  Memory Changed: None.
  1291.  
  1292. Routine        : CLRCH
  1293.  Kernal Address: $FFCC
  1294.  Description   : Restore default input and output channels.
  1295.  Registers In  : None.
  1296.  Registers Out : .A, .X used.
  1297.  Memory Changed: None.
  1298.  
  1299. Routine        : BASIN
  1300.  Kernal Address: $FFCF
  1301.  Description   : Read character from current input channel.
  1302.                  Cassette - Returned one character a time from cassette buffer.
  1303.                  Rs-232   - Return one character at a time, waiting until 
  1304.                             character is ready.
  1305.                  Serial   - Returned one character at time, waiting if nessc.
  1306.                  Screen   - Read from current cursor position.
  1307.                  Keyboard - Read characters as a string, then return them 
  1308.                             individually upon each call until all characters
  1309.                             have been passed ($0d is the EOL).
  1310.  Registers In  : None.
  1311.  Registers Out : .A = character or error code, .C = 1 if error.
  1312.  Memory Changed: None.
  1313.  
  1314. Routine        : BSOUT aka CHROUT
  1315.  Kernal Address: $FFD2
  1316.  Description   : Output byte to current channel
  1317.  Registers In  : .A = Byte
  1318.  Registers Out : .C = 1 if ERROR (examine READST)
  1319.  Memory Changed: Dependent upon current device.
  1320.  
  1321. Routine        : LOAD
  1322.  Kernal Address: $FFD5
  1323.  Description   : Loads file into memory (setup via SETLFS,SETNAM)..
  1324.  Registers In  : .A = 0 - Load, Non-0 = Verify
  1325.                  .XY = load address (if secondary address = 0)
  1326.  Registers Out : .A = error code .C = 1 if error.
  1327.                  .XY = ending address 
  1328.  Memory Changed: As per registers / data file.
  1329.  
  1330. Routine        : SAVE
  1331.  Kernal Address: $FFD8
  1332.  Description   : Save section of memory to a file.
  1333.  Registers In  : .A = Z-page ptr to start adress
  1334.                  .XY = end address
  1335.  Registers Out : .A = error code, .C = 1 if error.
  1336.                  .XY = used.
  1337.  Memory Changed: None.
  1338.  
  1339. Routine        : SETTIM
  1340.  Kernal Address: $FFDB
  1341.  Description   : Set internal clock (TI$).
  1342.  Registers In  : .AXY - Clock value in jiffies (1/60 secs).
  1343.  Registers Out : None.
  1344.  Memory Changed: Relevant system time locations set.
  1345.  
  1346. Routine        : RDTIM
  1347.  Kernal Address: $FFDE
  1348.  Description   : Reads internal clock (TI$)
  1349.  Registers In  : None.
  1350.  Registers Out : .AXY - Clock value in jiffies (1/60 secs).
  1351.  Memory Changed: None.
  1352.  
  1353. Routine        : STOP
  1354.  Kernal Address: FFE1
  1355.  Description   : Scans STOP key.
  1356.  Registers In  : None.
  1357.  Registers Out : .A = last keyboard row, .X = destroyed (if stop key)
  1358.  Memory Changed: None.
  1359.  Note          : The last keyboard row is as follows:
  1360.                  .A -> | 7   | 6   | 5   | 4   | 3   | 2   | 1  | 0
  1361.                   KEY: |STOP |Q    |C=   |SPACE|2    |CTRL |<-  |1
  1362.  
  1363. Routine       : GETIN
  1364.  Kernal Address: $FFE4
  1365.  Description   : Read buffered data from file.
  1366.                  Keyboard - Read from keyboard buffer, else return null ($00).
  1367.                  Rs-232   - Read from Rs-232 buffer, else null is returned.
  1368.                  Serial   - See BASIN
  1369.                  Cassette - See BASIN
  1370.                  Screen   - See BASIN
  1371.  Registers In  : None.
  1372.  Registers Out : .A = character, .C = 1 if error.
  1373.                  .XY = used.
  1374.  Memory Changed: None.
  1375.  
  1376. Routine       : CLALL
  1377.  Kernal Address: $FFE7
  1378.  Description   : Close all open files and channels.
  1379.  Registers In  : None.
  1380.  Registers Out : .AX used.
  1381.  Memory Changed: None.
  1382.  Note          : This routine does not _actually_ close the files, rather it
  1383.                  removes their prescense from the file tables held in memory.
  1384.                  It's recommended to use close to close files instead of using
  1385.                  this routine.
  1386.  
  1387.  
  1388. Routine        : UDTIME
  1389.  Kernal Address: $FFEA
  1390.  Description   : Update internal (TI$) clock by 1 jiffie (1/60 sec).
  1391.  Registers In  : None.
  1392.  Registers Out : .A,.X destroyed.
  1393.  Memory Changed: Relevant system time locations changed.
  1394.  
  1395. Routine        : SCRORG
  1396.  Kernal Address: $FFED
  1397.  Description   : Returns current window/screen size
  1398.  Registers In  : None.
  1399.  Registers Out : .X - Window Row Max
  1400.                  .Y - Window Col Max
  1401.                  .A - Screen Col Max (128 only, 64 unchanged)
  1402.  Memory Changed: None
  1403.  
  1404. Routine        : PLOT
  1405.  Kernal Address: $FFF0
  1406.  Description   : Read or set cursor position.
  1407.  Registers In  : .C = 1 (Read)        |      .C = 0 (Set)
  1408.                    None.              |        .X = Col
  1409.                                       |        .Y = Row
  1410.  Registers Out : .C = 1 (Read)        |      .C = 0 (Set) 
  1411.                    .X = Current Col   |         None.
  1412.                    .Y = Current Row   |
  1413.  Memory Changed:  None                |      Screen Editor Locations.
  1414.  
  1415. Routine        : IOBASE
  1416.  Kernal Address: $FFF3
  1417.  Description   : Returns base of I/O Block
  1418.  Registers In  : None.
  1419.  Registers Out : .XY = address of I/O block ($D000)
  1420.  Memory Changed: Screen Editor Locations.
  1421.  
  1422. ============================================================================
  1423. 64K VDC RAM and an alternate GEOS128 Background Screen
  1424. by Robert A. Knop Jr. (rknop@tybalt.caltech.edu, R.KNOP1 on GEnie)
  1425.  
  1426. I. Introduction
  1427.  
  1428. GEOS, both the 64 and 128 varieties, uses bitmapped screens for its output.
  1429. In 40 columns, this means 8K of system memory is set aside for the main
  1430. screen.  Then, in addition, GEOS also uses display buffering; in other words,
  1431. GEOS allocates a second 8K as a "background" (BG) screen that is used to keep
  1432. an intact copy of the foreground (FG) screen.  This can be very useful for a
  1433. number of reasons; one, it can be used as an undo buffer, as it is in
  1434. geoPaint.  When you have a delicate drawing, and then accidentally run the
  1435. eraser across it, the effects of the eraser are only written to the FG screen.
  1436. A click of the UNDO button brings the BG screen, with the pre-eraser version
  1437. of your painting, back to the fore.  Another use is for buffering the contents
  1438. of the screen when something like a dialog box or a menu is written over it.
  1439. When a dialog box is erased, and you see whatever had been underneatg it
  1440. magically reappear, the graphics underneath are being pulled from the BG
  1441. screen.
  1442.  
  1443. Applications have the option not to use the BG screen.  Change a couple of
  1444. vectors and flags, and you can use the 8K BG screen for application RAM.
  1445. (This is very convenient, since the BG screen is directly above the normal 22K
  1446. of application RAM in the GEOS memory map.)  Of course, the application then
  1447. has to provide some way of redrawing blocks of the screen hidden by menus and
  1448. dialog boxes.  geoWrite is an example of this; when you bring up, and exit
  1449. from, a dialog box in geoWrite, there is briefly a blank rectangle on the
  1450. screen before the text is redrawn on the screen.
  1451.  
  1452. Under GEOS128 in 80 columns, the bitmap screen is now twice as large: 640x200
  1453. instead of 320x200.  The FG screen, here 16K, occupies VDC memory.  The memory
  1454. used for both the 40 column FG and 40 column BG screen is used for the 80
  1455. column BG screen.
  1456.  
  1457. GEOS128 was written for, and runs on, 128's with only the usual 16K of VDC
  1458. RAM.  And, it uses basically all 16K of this RAM.  However, if you have 64K of
  1459. VDC RAM (as is the case with 128D's, and with flat 128's that have been
  1460. upgraded), you've got an additional 48K of VDC RAM that the GEOS system
  1461. doesn't touch.  So, why not use some of this RAM as a 80 column BG screen?
  1462. Then, if you are writing an 80-column only application, you get an extra 16K,
  1463. the 40-column BG screen at $6000 and the 40-column FG screen at $a000, in main
  1464. memory which your application can use however it sees fit.
  1465.  
  1466.  
  1467. II. Support Routines
  1468.  
  1469. Only a small number of routines actually need to be written to implement this
  1470. scheme; moreover, these routines are realatively straightforward.  After all,
  1471. we are simply copying memory from one part of VDC RAM to another.  The VDC's
  1472. block copy feature of the VDC is very helpful in this endeavor.  (See Craig
  1473. Taylor's article from last issue, or most any 128 programming guide.)  The
  1474. file vdc-bg.sfx, associated with this issue of the Hacking Mag, is a
  1475. self-extracting archive with a number of geoProgrammer source files (in
  1476. geoWrite 2.1 format) and a small dippy demonstration program.  The file VDC-BG
  1477. contains the following routines:
  1478.  
  1479. InitVDC       -- make sure your VDC knows it has 64K RAM
  1480. VDCImpLine    -- Imprint horizontal line from FG screen to BG screen
  1481. VDCRecLine    -- Recover horizontal line from BG screen to FG screen
  1482. VDCImpRect    -- Imprint rectangle from FG screen to BG screen
  1483. VDCRecRect    -- Recover rectangle from BG screen to FG screen
  1484.  
  1485. Each Imprint routine actually uses most of the same code as the corresponding
  1486. Recover routine; all that differs is the offset to the "source" and
  1487. "destination" screens in VDC RAM.  (The offset for the FG screen is $0000, and
  1488. for the BG screen is $4000.)  The routines take the same arguments as the
  1489. non-VDC Imprint and Recover routines as documented in the Hitchhiker's Guide.
  1490. (You will note, however, that for whatever reason the standard GEOS
  1491. ImprintLine and RecoverLine routines were only implemented for Apple GEOS.)
  1492. Briefly, these are:
  1493.  
  1494. Routine:     InitVDC
  1495.  
  1496. Pass:        Nothing
  1497.  
  1498. Return:      Nothing
  1499.  
  1500. Destroys:    a,x
  1501.  
  1502. Note:        This routine should be called at the very beginning of your
  1503.              program before you do any writing to the FG screen or the VDC.
  1504.  
  1505. ------------------------------------------------------------------------------
  1506.  
  1507.  
  1508. Routine:     VDCImpLine
  1509.              VDCRecLine
  1510.  
  1511. Pass:        r3   -- left edge of line to imprint/recover (word)
  1512.              r4   -- right edge of line to imprint/recover (word)
  1513.              r11L -- y coordinate of line to imprint/recover (byte)
  1514.  
  1515. Return:      r3, r4 -- processed through NormalizeX
  1516.  
  1517. Destroys:    a,x,y,r5-r8,r11
  1518.  
  1519. -------------------------------------------------------------------------------
  1520.  
  1521. Routine:     VDCImpRect
  1522.              VDCRecRect
  1523.  
  1524. Pass:        r3   -- x-coordinate of upper-left corner (word)
  1525.              r2L  -- y-coordinate of upper-left corner (byte)
  1526.              r4   -- x-coordinate of lower-right corner (word)
  1527.              r2H  -- y-coordinate of lower-right corner (byte)
  1528.  
  1529. Return:      r3,r4 -- processed through NormalizeX
  1530.  
  1531. Destroys:    a,x,y,r5-r8,r10L,r11
  1532.  
  1533. ------------------------------------------------------------------------------
  1534.  
  1535.  
  1536. To discuss the imprint and recover line routines, consider the ASCII diagram
  1537. of a portion of a line on the VDC screen.  A x indicates a pixel that is in
  1538. the line to be copied.  The I's indicate byte boundaries; the pixel below each
  1539. I is the msb of the corresponding byte in the VDC bitmap.  (Bytes increase
  1540. horizontally across the screen; there is no card structure found in the 80
  1541. column bitmap screen.)
  1542.  
  1543.            I       I       I       I
  1544.            ....xxxxxxxxxxxxxxxxxxxxxxxxx...
  1545.                 ^  \______________/  ^
  1546.              left          I         right
  1547.           residual     full bytes    residual
  1548.  
  1549. The line moving routine needs to figure the location in VDC RAM of the
  1550. leftmost full byte, the number of full bytes, and the location of the two
  1551. residual bytes; additionally, it builds a bit mask for the residual bytes,
  1552. with bits set corresponding to pixels to be copied.  This mask is used to
  1553. create the proper combination of data from the source and destination screens
  1554. in the two residual bytes.
  1555.  
  1556. Once it knows all this, all the line routines do is (1) submit a VDC block
  1557. copy to copy the full bytes, (2) read the left residual byte from the source,
  1558. mask out the appropriate pixels, and OR it with the appropriate pixels from
  1559. the destination, and write that one byte (3) repeat (2) for the right residual
  1560. byte.
  1561.  
  1562. The rectangle routines simply call the line copy routines repeatedly,
  1563. (r2H)-(r2L)+1 times.  (Note that while this is the most efficient way to do it
  1564. from a coding time point of view <grin>, really the rectangle routines only
  1565. need calculate the residual bit masks and the locations once.  Thereafter,
  1566. locations can be updated by adding 80 (the length of a VDC line) for each new
  1567. line.  The changes to the code to implement this are not difficult, and it
  1568. isn't clear why I didn't make them....)
  1569.  
  1570.  
  1571. III. Use of the Routines
  1572.  
  1573. In a word, you use these routines whenever you would have used the normal GEOS
  1574. imprint/recover routines.  There are a few other consierations, though.
  1575.  
  1576. First of all, you need to set the flag dispBufferOn to ST_WR_FORE.  The GEOS
  1577. system graphic routines think that the BG screen is in main memory, and thus
  1578. will not correctly use your new VDC BG screen.  This means, unfortunately,
  1579. that you can't just blithely go drawing graphics, assuming that they'll be
  1580. buffered for recall when needed.  However, it is not too much trouble to make
  1581. a call to VDCImpRect either right after you've made some graphic change, or
  1582. right before something potentially hazardous will happen (e.g. a call to
  1583. DoDlgBox).  For instance, you might have all of your main menus be Dynamic
  1584. Submenus which call VDCImpRect before opening the submenu.
  1585.  
  1586. Second, you should load recoverVector with VDCRecRect.  Since VDCRecRect takes
  1587. the same parameters as RecoverRectangle, it can substitute directly for it.
  1588. Once you set this vector, all menus and dialog boxes erased from the screen
  1589. automatically restore the destroyed region from your VDC BG screen.
  1590.  
  1591. Both of these are demonstrated in the test program included in vdc-bg.sfx.
  1592.  
  1593.  
  1594. IV. Another 32K
  1595.  
  1596. The alert reader will have noticed that the VDC BG screen only takes as much
  1597. memory as the VDC FG screen, i.e. 16K.  Thus, even with this scheme, there is
  1598. still another 32K of free memory in VDC RAM.  Quadruple buffering, anyone?
  1599.  
  1600. A more tantalizing prospect would be to implement a 640x400 interlaced screen
  1601. for GEOS128.  This presents a number of problems, however.  First, there is
  1602. that terrible flicker.  But, this can be made reasonable through the use of
  1603. polarizing filters (in layman's terms, "sunglasses") and appropriate color
  1604. choices.  More seriously, the GEOS kernal graphic routines all take byte
  1605. argum`>:s for Y coordinates.  So, all 400 vertical pixels cannot be addressed
  1606. with those routines.  Thus, sombody implementing a GEOS interlaced screen is
  1607. faced with re-writing all of the graphics routines.  (Something to do with the
  1608. 8K you've freed up at $a000, I suppose.)  Since each 640x400 graphic screen
  1609. would require 32K of memory for the bitmap, you could still have a VDC
  1610. Background screen.
  1611.  
  1612. [ Note: The code discussed within this article is available via anonymous 
  1613. FTP at tybalt.caltech.edu under the directory pub/rknop/hacking.mag as 
  1614. vdc-bg.sfx. This will dissolve into the GEOWRITE source files.]
  1615.  
  1616. ============================================================================
  1617.  
  1618. GeoPaint File Format
  1619. --------------------
  1620. by Bruce Vrieling (bvrieling@undergrad.math.waterloo.edu)
  1621.  
  1622. GeoPaint is an excellent graphics program written for the GEOS environment. Its
  1623. disk access is relatively quick, compared it to what a comparable program would
  1624. do on a non-GEOS equipped C64. Part of this accomplishment can be attributed to
  1625. the diskTurbo that is an integral part of GEOS. However, the special GeoPaint
  1626. file-saving scheme deserves some of the credit.
  1627.  
  1628.  
  1629. VLIR
  1630. ----
  1631.  
  1632. GeoPaint files are always stored in Variable Length Indexed Recording files. 
  1633. VLIR files offer advantages not available without GEOS. Generally speaking, VLIR
  1634. is the ultimate in RELATIVE files.
  1635.  
  1636. The format of a VLIR file is not that difficult to figure out. While in a 
  1637. regular C64 file, the two bytes directly following the FILETYPE byte in the 
  1638. directory would point to the data file following, VLIR files use these two bytes
  1639. to point to a VLIR HEADER BLOCK (don't confuse the VLIR HEADER block with the
  1640. INFO block). The first two bytes of this block are $00/FF, as the header block 
  1641. is a MAXIMUM of one block long. (This is why when you VALIDATE a GEOS disk from
  1642. C64 mode, GeoPaint pictures are lost. Only the header block is recognised as 
  1643. being part of the file. The rest of the picture gets deallocated in the BAM). 
  1644. The remaining 254 bytes in the block are divided into 127 2-byte pointers to 
  1645. tracks/sectors on the disk. These pointers point to the individual records of 
  1646. the VLIR file, which may be ANY number of blocks long. The VLIR track/sector 
  1647. pointers in the VLIR header block only point to the FIRST block of the chain. 
  1648. From then on, the sectors chain themselves together using the normal format ie.
  1649. the first two bytes of each block point to the following block.
  1650.  
  1651. A sample GeoPaint VLIR header might look like this:
  1652.  
  1653. 0000:00 FF 03 11 03 05 03 01 ........
  1654. 0008:04 03 00 FF 00 FF 00 FF ........
  1655. 0010:04 07 00 00 00 00 00 00 ........
  1656.  etc....
  1657.  
  1658. The first two bytes, $00/FF, tell the drive that this is the last (and only) 
  1659. block in this VLIR HEADER SECTION (will never be more than 1 block, as was 
  1660. mentioned earlier). The next pair of bytes, $03/11, points to the first VLIR 
  1661. record. The next two, $03/05, point to the second record.
  1662.  
  1663. You will notice that 5th record contains the values $00/FF. This means that for
  1664. this record, there is no picture data. We will get into exactly what the data 
  1665. held in the records mean in a minute. The $00/FF entries indicate an empty 
  1666. record. Finally, the 9th entry, $00/00 indicates the end of the GeoPaint file.
  1667. There is no more data beyond this point.
  1668.  
  1669. One note should be made. GeoPaint is not always consistent in its handling of 
  1670. the data in a header block. Sometimes, it will show quite a few $00/FF 
  1671. combinations before finally terminating with a $00/00. When reading the file, 
  1672. I always read the entire header, as I don't trust the end of file method 
  1673. mentioned above. Just remember that any track/sector link that does not contain
  1674. $00/FF or $00/00 is a valid record, with picture data.
  1675.  
  1676.  
  1677. Layout on Screen
  1678. ----------------
  1679.  
  1680. GEOS orients the data in a GeoPaint file slightly differently than in a 
  1681. PhotoScrap or an Icon. A photoscrap stores the bytes corrosponding to a screen
  1682. which looks like this:
  1683.  
  1684. 001 002 003 004 005 ....0012
  1685. 013 014 015 016 017 ....0024
  1686.  
  1687. Consecutive bytes are placed BESIDE each other. However, if you are at all
  1688. familiar with the layout of a C64 hi-res screen, you will know this is very 
  1689. different from the layout that the VIC chip sees data. GeoPaint uses a format 
  1690. identical to the VIC chip layout on screen.
  1691.  
  1692. GeoPaint pictures are stored in the following format:
  1693.  
  1694. 001 009 017 025 033 .....  313
  1695. 002 010 018 026 034 .....  314
  1696. 003 011 019 027 035 .....  315
  1697. 004 012 020 028 036 .....  316
  1698. 005 013 021 029 037 .....  317
  1699. 006 014 022 030 038 .....  318
  1700. 007 015 023 031 039 .....  319
  1701. 008 016 024 032 040 .....  320
  1702.  
  1703. 321 329 .....
  1704. 322 330 .....
  1705. 323 331 .....
  1706. 324 332 .....
  1707. 325 333 .....
  1708. 326 334 .....
  1709. 327 335 .....
  1710. 328 336 .....
  1711.  
  1712. As you can see, this is very different from the PhotoScrap format. Consecutive
  1713. bytes are NOT stored on the screen beside each other. Rather, they are stored
  1714. underneath each other into groups of 8 bytes. This makes moving the data from 
  1715. the disk onto the screen that much faster, as the decompacted bytes can just be
  1716. stored on the screen after each other. Of course, this makes porting GEOS pics
  1717. to the 128's VDC that much more difficult, as the VDC conforms to the 
  1718. PhotoScrap format.
  1719.  
  1720.  
  1721. Compression Method
  1722. ------------------
  1723.  
  1724. GEOS uses an excellent compression method to store files on disk. You may have
  1725. noticed that nearly empty pictures on disk consume very little disk space. This
  1726. can be credited to GeoPaint's smart compression techniques.
  1727.  
  1728. Basically, the format of the compression has one COMMAND byte followed by one 
  1729. or more DATA bytes. The COMMAND byte tells GEOS what to do with following DATA 
  1730. bytes. There are 4 commands for compression:
  1731.  
  1732. 1) If the COMMAND byte is less than 64, this indicates that there are 'COMMAND'
  1733.    many DATA bytes following that are to be taken as individual bytes. This is
  1734.    the least effective method of compression, as no compression takes place.
  1735.  
  1736. 2) If the COMMAND byte ranges from 65 to 127, then this is a special type of 
  1737.    compression. First of all, the next 8 bytes in the file are read in as DATA.
  1738.    This DATA is used to make an 8*8 'stamp'. Secondly, the amount of times to 
  1739.    'stamp' this 8*8 square is calculated (COMMAND AND 63). Then, the stamping 
  1740.    is done. 'Stamping' sounds more difficult that it really is. What it boils
  1741.    down to, is repeating the 8 byte DATA stamp 'COMMAND AND 63'
  1742.    times.
  1743.  
  1744. 3) If the COMMAND byte is 129 or greater, then the following DATA byte is
  1745.    repeated 'COMMAND AND 127' times. This is different from #1, as only 1 DATA
  1746.    byte is called in, and simply repeated. #1 called in 'COMMAND' many DATA 
  1747.    bytes.
  1748.  
  1749. 4) If the COMMAND byte is ZERO, we have reached the end of the VLIR record for
  1750.    the GeoPaint picture.
  1751.  
  1752. It should be noted that the COMMAND byte will NEVER be 64 or 128. If it is, 
  1753. there has been an error.
  1754.  
  1755.  
  1756. Format of Data After Decompacting
  1757. ---------------------------------
  1758.  
  1759. After the data has been decompacted, it remains to be placed on the screen. Each
  1760. VLIR record holds 16 scanlines of data, or 2 character lines (different ways of
  1761. looking at the same thing).
  1762.  
  1763. The format of the data is as follows:
  1764.  
  1765.      First, there is 640 bytes of picture data, comprising the first character
  1766.      line (8 scanlines). Remember, GeoPaint pictures are 640 pixels across. 640
  1767.      pixels works out to 80 bytes. A character line is 8 pixels deep, so 80*8 
  1768.      comes to 640 bytes.
  1769.  
  1770.      These bytes are followed by the 640 bytes for the second chacacter line 
  1771.      (next 8 scanlines). This is followed by 8 garbage bytes that accidentaly 
  1772.      worked themselves into the original GeoPaint design. They should be set to
  1773.      zero.
  1774.  
  1775.      Finally, two sets of 80 bytes of colour data follow. The first set 
  1776.      comprises the colour for the first line, the second 80 bytes for the second
  1777.      line. To wrap things up, the VLIR record is terminated by a zero byte.
  1778.  
  1779.      The next VLIR record will hold the data for the NEXT 16 scanlines, and so
  1780.      on.
  1781.  
  1782.  
  1783. Conclusion
  1784. ----------
  1785.  
  1786. That about wraps up this discussion on GeoPaint format for files. We've 
  1787. discussed the format of VLIR files on disk, layout of picture data on screen, 
  1788. compression methods used in GeoPaint files, and the format of the data once 
  1789. decompacted. I hope this information will come in handy for someone.
  1790.  
  1791. ==============================================================================
  1792. Rasters - What They Are and How to Use Them
  1793. by Bruce Vrieling - (bvrieling@undergrad.math.waterloo.edu)
  1794.  
  1795. Anyone who has fiddled around with interrupts on the Commodore 64 has 
  1796. undoubtedly heard at one time or another of the concept of rasters being 
  1797. mentioned. Rasters are the 'ultimate' achievement of interrupt programming, or
  1798. so they say. What is a raster? And how does one go about writing a program to 
  1799. use them?
  1800.  
  1801. Overview of what Interrupts are all about
  1802. -----------------------------------------
  1803.  
  1804. A raster is sort form for the concept of a 'raster interrupt'. Before
  1805. going into rasters, perhaps a brief review of interrupts is in order.
  1806.  
  1807. Interrupts are events generated by the CIA timer in the C64 to perform certain 
  1808. tasks. 60 times a second, the CIA chip signals an interrupt is due to be 
  1809. processed (ie. the interrupt timer timed out). This causes the 6510 CPU to stop
  1810. executing the current program, save the registers on the stack, and begin to 
  1811. execute the interrupt code. Some of the things which get done during an 
  1812. interrupt include the keyboard scan, and updating TI (the software clock). When
  1813. the interrupt code is finished, an RTI instruction is executed, which brings 
  1814. the interrupt's execution to a halt. The registers are retrieved from the stack,
  1815. and the current program in memory continues to execute once again. It will 
  1816. continue to do so until the next interrupt occurs, about 1/60 of a second later.
  1817.  
  1818. The above is what happens in a normal C64 (the C128 follows the same idea, but 
  1819. more events occur during a C128 interrupt). [Ed. Note: In addition, the C=128
  1820. generates its interrupts via a screen raster instead of the CIA chip.]
  1821.  
  1822. However, you can change the normal course of events, and cause some code of your
  1823. design to be added to the normal list of events which occur every interrupt. 
  1824. Some of the simple favourites include flashing the border 60 times per second.
  1825. (Note that we have not begun the topic of rasters yet; this has nothing to do
  1826. with rasters. That discussion begins at the next heading.)
  1827.  
  1828. How do you change the interrupt's normal course of action? It's rather simple.
  1829. The C64 contains an interrupt VECTOR at locations 788/9 which is 'jumped 
  1830. through' before the Kernal Rom gets a chance to execute its code. If you change
  1831. this vector to point to YOUR code, and make the end of your code point to the 
  1832. normal Kernal location (where the interrupt normally would have jumped to, 
  1833. $EA31), and you are careful not to step on anything, your code will be executed
  1834. 60 times per second.
  1835.  
  1836. An example is in order:
  1837.  
  1838. ; flasher
  1839. ;
  1840. ; this program causes the border to flash 60 times per second
  1841. ;
  1842. setup = *
  1843.  
  1844. sei                           ; disable interrupts
  1845. lda #<intcode                 ; get low byte of target routine
  1846. sta 788                       ; put into interrupt vector
  1847. lda #>intcode                 ; do the same with the high byte
  1848. sta 789
  1849. cli                           ; re-enable interrupts
  1850. rts                           ; return to caller
  1851.  
  1852. intcode = *
  1853.  
  1854. inc $d020                     ; change border colour
  1855. jmp $ea31                     ; exit back to rom
  1856.  
  1857.  
  1858. The above is an example of a very simple interrupt routine. If you were to 
  1859. assemble it with an assembler, and SYS to the SETUP routine, you would see your
  1860. border flash 60 times per second.
  1861.  
  1862. You will notice the SEI and CLI machine language instructions used above. They
  1863. are very important. We don't want an interrupt occurring in between the STA 788
  1864. and the STA 789 instructions.
  1865.  
  1866. Think what would happen if one did: 788 would have been modified, but 789 would
  1867. still be pointing to the high byte of the Kernal address. Result: the interrupt
  1868. would have jumped to heaven knows where. You can be virtually guaranteed that 
  1869. it would NOT be pointing to a valid piece of interrupt code. Your machine would
  1870. crash. The SEI instruction turns interrupts OFF, so that there is no danger of 
  1871. an interrupt occurring during execution of the following routine. The CLI turns
  1872. them back on. If you forget to turn them back on, and accidentally leave them 
  1873. off, your keyboard will freeze when you return to basic, and your machine will
  1874. seem to lock up.
  1875.  
  1876. The above was a very simple example. There are many useful things which can also
  1877. be done on an interrupt. I have seen code which played music in the background
  1878. of a running Basic program (it played the popular .MUS files). GEOS uses 
  1879. interrupts extensively to control the pointing of the mouse, and to trigger 
  1880. events. Interrupts are powerful beasts, and the following concept concerning 
  1881. raster interrupts specifically is a particularly useful animal for some people.
  1882.  
  1883.  
  1884. The Raster
  1885. ----------
  1886.  
  1887. A raster is a loosely used term. It refers to an interrupt that is triggered 
  1888. when the ray gun on the back of your monitor draws a certain line on the video
  1889. screen. There are many different sources which can cause an interrupt. You are 
  1890. not limited to what the CIA chip can do. Rasters depend on interrupts 
  1891. specifically generated by the VIDEO chip. You could make this interrupt change
  1892. the border colour of the screen below a certain screen line. When the screen 
  1893. line you specified gets redrawn, the interrupt goes off. Your code then quickly
  1894. changes some memory locations to create a different video mode or effect. You 
  1895. could cause the bottom half of the screen to gets it's character definitions 
  1896. from another, different character set. Or, you could make the top 3/4 of your 
  1897. screen exist in hi-res multi-colour graphics, and keep the bottom 1/4 of the 
  1898. screen in text mode.
  1899.  
  1900. Some facts about the video screen: it gets redrawn exactly 60 times per second.
  1901. It contains 200 scan lines on the normal 25*40 display, numbered 50 to 250 or 
  1902. thereabouts (note that there are more visible scan lines though: the top and 
  1903. bottom borders, for example). The actual re-drawing of the screen is 
  1904. synchronized to the electrical power coming into your house, 60 Hz. That's why
  1905. some programs behave differently when run on European machines. The power is 
  1906. delivered at 50 Hz over there.
  1907.  
  1908. Why do we have to worry about a video interrupt? If the screen gets redrawn 60
  1909. times per second, and regular interrupts also occur at 60 times per second, why
  1910. not simply put some code into the regular interrupt to do what we want with the
  1911. screen? Because the two types of interrupts are not in sync. Neither one of them
  1912. occurs EXACTLY 60 times per second, and the differences are enough to make it 
  1913. next to impossible to get coordinated activity of any kind happening on the 
  1914. screen. When we use the video interrupt, we KNOW we are at a certain line on the
  1915. screen, as being on that line is what caused the interrupt to happen in the
  1916. first place.
  1917.  
  1918. So, let's summarize. We know that regular interrupts occur 60 times per second.
  1919. We also know that the video screen gets re-drawn 60 times per second, and that
  1920. we can cause an interrupt to be generated when a certain line gets drawn on the
  1921. screen. One slight drawback to all of this is that BOTH types of interrupts
  1922. (regular and raster driven) travel through the SAME vector (ie. about 120 
  1923. interrupts per second, 60 of one, and 60 of the other). Your code will have to
  1924. check and see what the source of the interrupt was, and act accordingly. Or will
  1925. it?
  1926.  
  1927. The system needs an interrupt to occur 60 times per second to do housekeeping,
  1928. and uses the CIA clock to generate the interrupts. We want to interrupt every 
  1929. time a certain scan line is reached on the monitor, which will also just happen
  1930. to occur at 60 times per second. We also have to make sure that they don't 
  1931. interfere with each other. The regular interrupts should be sent to their Rom
  1932. destination, while our video interrupts should go to our code, and no where 
  1933. else.
  1934.  
  1935. If both are occurring at 60 times per second, why not do the job of the system
  1936. Rom, and our video code on the SAME interrupt? We know that the CIA chip is not
  1937. good for this; it is out of sync with the video image. Why not turn OFF the CIA
  1938. interrupt, enable the raster/video interrupt, and do both jobs on one interrupt?
  1939. Then we would have an interrupt signal that occurs 60 times per second, and is
  1940. in perfect sync with the video image.
  1941.  
  1942. That's exactly what we're going to do.
  1943.  
  1944. Astute reads will notice a slight flaw in the above logic. For simplification 
  1945. purposes, I didn't get into the fact that you will need TWO raster interrupts 
  1946. PER SCREEN to accomplish anything useful. Why two? Because any change to the 
  1947. video mode you put into effect 3/4 of the way down the screen will have to be 
  1948. undone at the TOP of the next screen update. If you decide to make the top 3/4 
  1949. of the screen a hi-res image, and the bottom 1/4 text, you need one interrupt 
  1950. 3/4 of the way down the screen to change from hi-res to text, but you need a 
  1951. SECOND one at the top of the screen to change back to hi-res from text.
  1952.  
  1953. So, we will now have 120 interrupts going off every second to accomplish our 
  1954. video desires, with 60 of them working a double shift, making sure the system 
  1955. interrupt code gets executed also. Remember that we are working with a specific
  1956. example. There is no reason why you couldn't split the screen into N different
  1957. video modes, and have (N+1)*60 interrupts going off per second. As long as you 
  1958. keep your code short (so your interrupts don't take too long, and have another 
  1959. interrupt occur before the current one is done - messy), it will work 
  1960. beautifully.
  1961.  
  1962. So far, this is all talk. Let's write a few short code segments to accomplish 
  1963. some of the feats we've just discussed.
  1964.  
  1965. The first we'll do is a re-hash of the one presented above. It flashes the 
  1966. border again. It does not do any mid-screen changes of video modes or anything 
  1967. fancy like that, so only 1 interrupt per screen is required (ie. 60 per second,
  1968. not 120 etc.). This program simply shows the same idea, but this time using 
  1969. video interrupts as the source rather than the CIA. You probably won't
  1970. notice a difference during execution.
  1971.  
  1972. ----------------------------------------------------------------------------
  1973. ; flasher - part II
  1974. ;
  1975. ; this program causes the border to flash 60 times per second
  1976. ; the source of the interrupts is the video chip
  1977. ;
  1978. setup = *
  1979.  
  1980. sei                           ; disable interrupts
  1981.  
  1982. lda #$7f                      ; turn off the cia interrupts
  1983. sta $dc0d
  1984.  
  1985. lda $d01a                     ; enable raster irq
  1986. ora #$01
  1987. sta $d01a
  1988.  
  1989. lda $d011                     ; clear high bit of raster line
  1990. and #$7f
  1991. sta $d011
  1992.  
  1993. lda #100                      ; line number to go off at
  1994. sta $d012                     ; low byte of raster line
  1995.  
  1996. lda #>intcode                 ; get low byte of target routine
  1997. sta 788                       ; put into interrupt vector
  1998. lda #<intcode                 ; do the same with the high byte
  1999. sta 789
  2000. cli                           ; re-enable interrupts
  2001. rts                           ; return to caller
  2002.  
  2003.  
  2004. intcode = *
  2005.  
  2006. inc $d020                     ; change border colour
  2007.  
  2008. lda $d019                     ; clear source of interrupts
  2009. sta $d019
  2010.  
  2011. lda #100                      ; reset line number to go off at
  2012. sta $d012
  2013.  
  2014. jmp $ea31                     ; exit back to rom
  2015. --------------------------------------------------------------------------
  2016.  
  2017. As you can tell, there's a wee bit more to this code than there was in the 
  2018. original. Execute it, and you'll notice that it looks pretty much the same as 
  2019. the results from the first program. But there's a difference: the interrupts 
  2020. are now being generated from the video chip, not the CIA. For this program, it 
  2021. didn't make much difference. However, for a more complicated program, it makes
  2022. a world of difference.
  2023.  
  2024. I'd better explain some of the code used above:
  2025.  
  2026.      lda #$7f
  2027.      sta $dc0d
  2028.  
  2029.      - This piece disables any interrupts caused by the CIA chip.
  2030.  
  2031.      lda $d01a
  2032.      ora #$01
  2033.      sta $d01a
  2034.  
  2035.      - Location $d01a controls which sources may cause an interrupt
  2036.        (other than the normal CIA). There are 4 different possible
  2037.        sources: rasters, sprite to sprite collision, sprite to
  2038.        background collision, and the light pen. Bit #0 is the raster
  2039.        bit, and this piece of code activates it.
  2040.  
  2041.      lda $d011
  2042.      and #$7f
  2043.      sta $d011
  2044.  
  2045.      - This code clears bit #7 of location $d011. This location is used
  2046.        for many different things. Bit #7 represents the highest bit of
  2047.        the raster line (see segment below for more on the raster line
  2048.        #). More than 256 raster line numbers are possible (some are off
  2049.        screen, and some represent the upper and lower border areas).
  2050.        This bit is the 9th bit. I set it to zero because all my code
  2051.        affects rasters only on the normal 25*40 line display, well
  2052.        within the 0-255 range. This decision was an arbitrary choice on
  2053.        my part, to make the code simpler.
  2054.  
  2055.      lda #100
  2056.      sta $d012
  2057.  
  2058.      - Location $d012 is the lower 8 bits of the raster line on which
  2059.        the interrupt is to be generated. The number 100 was another
  2060.        arbitrary choice. For changing border colours, the actual line
  2061.        number was not important. Later on, in the next example, it will
  2062.        become important.
  2063.  
  2064.      lda #>intcode
  2065.      ...
  2066.      rts
  2067.  
  2068.      - Re-vectors the interrupt code to the new code.
  2069.  
  2070.      inc $d020
  2071.  
  2072.      - Changes the border colour.
  2073.  
  2074.      lda $d019
  2075.      sta $d019
  2076.  
  2077.      - These lines clear the bit in the interrupt register which tells the
  2078.        source of the interrupt (in preperation for the next).
  2079.  
  2080.      lda #100
  2081.      sta $d012
  2082.  
  2083.      - This line resets the raster line to go off at line number 100
  2084.        again (same as above). It should be reset, so the next interrupt
  2085.        will know what line to occur on.
  2086.  
  2087.      jmp $ea31
  2088.  
  2089.      - Exit back to the Kernal Rom.
  2090.  
  2091.  
  2092. A Useful Example
  2093. ----------------
  2094.  
  2095. The following is an example of a more sophisticated piece of raster code. It 
  2096. makes the top half of the screen border white, and the bottom half black.
  2097.  
  2098. ---------------------------------------------------------------------------
  2099. setup = *
  2100.  
  2101. ; some equates
  2102.  
  2103. COLOUR1 = 0
  2104. COLOUR2 = 1
  2105. LINE1 = 20
  2106. LINE2 = 150
  2107.  
  2108. ; code starts
  2109.  
  2110. setup = *
  2111.  
  2112. sei                           ; disable interrupts
  2113.  
  2114. lda #$7f                      ; turn off the cia interrupts
  2115. sta $dc0d
  2116.  
  2117. lda $d01a                     ; enable raster irq
  2118. ora #$01
  2119. sta $d01a
  2120.  
  2121. lda $d011                     ; clear high bit of raster line
  2122. and #$7f
  2123. sta $d011
  2124.  
  2125. lda #LINE1                    ; line number to go off at
  2126. sta $d012                     ; low byte of raster line
  2127.  
  2128. lda #>intcode                 ; get low byte of target routine
  2129. sta 788                       ; put into interrupt vector
  2130. lda #<intcode                 ; do the same with the high byte
  2131. sta 789
  2132.  
  2133. cli                           ; re-enable interrupts
  2134. rts                           ; return to caller
  2135.  
  2136. intcode = *
  2137.  
  2138. lda modeflag                  ; determine whether to do top or
  2139.                               ; bottom of screen
  2140. beq mode1
  2141. jmp mode2
  2142.  
  2143. mode1 = *
  2144.  
  2145. lda #$01                      ; invert modeflag
  2146. sta modeflag
  2147.  
  2148. lda #COLOUR1                  ; set our colour
  2149. sta $d020
  2150.  
  2151. lda #LINE1                    ; setup line for NEXT interrupt
  2152. sta $d012                     ; (which will activate MODE2)
  2153.  
  2154. lda $d019
  2155. sta $d019
  2156.  
  2157. jmp $ea31                     ; MODE1 exits to Rom
  2158.  
  2159. mode2 = *
  2160.  
  2161. lda #$00                      ; invert modeflag
  2162. sta modeflag
  2163.  
  2164. lda #COLOUR2                  ; set our colour
  2165. sta $d020
  2166.  
  2167. lda #LINE2                    ; setup line for NEXT interrupt
  2168. sta $d012                     ; (which will activate MODE1)
  2169.  
  2170. lda $d019
  2171. sta $d019
  2172.  
  2173. pla                           ; we exit interrupt entirely.
  2174. tay                           ; since happening 120 times per
  2175. pla                           ; second, only 60 need to go to
  2176. tax                           ; hardware Rom. The other 60 simply
  2177. pla                           ; end
  2178. rti
  2179.  
  2180. modeflag .byte 0
  2181.  
  2182. ----------------------------------------------------------------------------
  2183.  
  2184. The above code, when executed, will result in the top half of your border being
  2185. white, and the bottom black. You may wish to fiddle with the equates (COLOUR1,
  2186. COLOUR2, LINE1, and LINE2) to get different effects.
  2187.  
  2188. I see some confused faces concerning why the above exit the interrupts the way 
  2189. they do. Remember, since we want a split screen effect, we have to have one 
  2190. interrupt occur at the TOP of the screen, to turn on the WHITE effect, and one 
  2191. midway down to turn on the BLACK effect. Two interrupts times 60 means 120
  2192. interrupts will be executed per second. The Rom only needs 60 per second to 
  2193. service the keyboard and its other stuff. So, we send 60 to the Rom (the 
  2194. interrupts which go through MODE1) by JMPing to $EA31, and the other 60 we 
  2195. trash. The PLA... RTI business is the proper way to bring an interrupt to an end
  2196. without going through the Rom. The RTI will ReTurn from Interrupt, and cause the
  2197. regular program to continue to execute.
  2198.  
  2199. That brings to an end this discussion on rasters. I hope the above examples 
  2200. have proved to be a valuable learning tool for you. With luck, they will 
  2201. motivate you to continue to experiment with rasters, and come up with some neat
  2202. effects.
  2203.  
  2204. If you have any questions, be sure to ask me about them.
  2205.  
  2206. ==============================================================================
  2207. BURSTING YOUR 128: THE FASTLOAD BURST COMMAND
  2208. by Craig Bruce <f2rx@jupiter.sun.csd.unb.ca>
  2209.  
  2210. 1. INTRODUCTION
  2211.  
  2212. This article discusses the well-unknown Fastload command of the 1571 and 1581
  2213. disk drive Burst Command Instruction Set.  If you look in the back of your '71
  2214. (or '81 I presume) disk drive manual, you will find that the information given
  2215. about the Fastload utility is not exactly abundant.
  2216.  
  2217. The Fastload command was intended to load program files into memory for
  2218. execution, but it can be used just as well for reading through sequential
  2219. files that would be much too large to load into a single bank of internal
  2220. memory.
  2221.  
  2222. To make use of the Fastload burst command, I implement a word counting utility
  2223. that will count the number of lines, words, and characters in a text file on a
  2224. 1571 or 1581 disk drive.  The advantage of using the Fastload command over
  2225. regular sequential file accessing through the kernel and DOS is that the
  2226. Fastload operates about 3.5 times faster on both drives.
  2227.  
  2228. 2. WORD COUNTING UTILITY
  2229.  
  2230. To use the word counting program, LOAD and RUN it like a regular BASIC
  2231. program.  It will ask you for the name of a file.  Enter the name if it is on
  2232. device number 8, or put a one character prefix and a ":" if it is on another
  2233. device.  A "b" means device 9, "c" device 10, etc.  The following are examples
  2234. of valid names:
  2235.  
  2236. . filename          "filename" on device 8
  2237. . b:filename        "filename" on device 9
  2238. . a:filename        "filename" on device 8
  2239.  
  2240. The file must be on either a 1571 or 1581 disk drive; the program will not
  2241. work with non-burst devices.  The program will work with either PRG or SEQ
  2242. files, since the Fastload command can be told not to worry about the file
  2243. type.
  2244.  
  2245. I use the same definition of a word as the Unix "wc" command uses: a sequence
  2246. of characters delimited by whitespace, where whitespace is defined to be
  2247. SPACE, TAB, and NEWLINE (Carriage Return) characters.  To get the line count,
  2248. I simply count the number of NEWLINEs.  If the last line of the file does not
  2249. end with a NEWLINE character, then the count will be one line short.  This is
  2250. the same as the Unix wc command too.  A proper text file should have its last
  2251. line end with a NEWLINE character.
  2252.  
  2253. On my JiffyDOS-ified 1571 and 1581, I am able to achieve a word counting speed
  2254. of 5,400 chars/sec and 6,670 chars/sec, respectively.  I am not sure how much
  2255. of a difference JiffyDOS makes, but I am not willing to rip out the ROMs to
  2256. check.  I tested using a 318K file.
  2257.  
  2258. 3. BURST READ LIBRARY
  2259.  
  2260. This section presents the burst reading library that you can incorporate into
  2261. your own programs and describes how the burst commands work.  The library has
  2262. three calls:
  2263.  
  2264. . burstOpen  ( .A=Device, .X=NameLen, burstBuf=Filename ) : <first block>
  2265. . burstRead  () : burstBuf, burstStatus, burstBufCount
  2266. . burstClose ()
  2267.  
  2268. I define three common storage variables for using this package: "burstBuf",
  2269. "burstStatus", and "burstBufCount".  "burstBuf" is a 256 byte area where the
  2270. data read in from the disk drive is stored before processing, and is located
  2271. at $0B00.  "burstStatus" is a zero-page location that keeps the status
  2272. returned from the burst command system.  This is needed by the user to detect
  2273. when the end of file has been encountered.  "burstBufCount" gives the number
  2274. of data bytes available in "burstBuf" after an open or read operation.  Its
  2275. value will be somewhere between 1 and 254.  A full sector contains 254 bytes
  2276. of data and two bytes of control information.
  2277.  
  2278. "burstStatus" and "burstBufCount" are defined to be at locations $FE and $FF,
  2279. respectively.  You are allowed to alter the values of the two variables and
  2280. the data buffer between calls, if you wish.  For reasons not completely
  2281. understood, interrupts must be disabled for the entire course of burst reading
  2282. a file.  I suspect this is because the IRQ service routine reads the interrupt
  2283. mask register of CIA#1, thus clearing the SerialDataReady flag that the burst
  2284. read routine waits for.  Anyway, the open routine does a SEI and the close
  2285. routine does a CLI, so you don't have to do this yourself.
  2286.  
  2287. If an error occurs during the exection of one of these routines, it will
  2288. return with the carry flag set and with the error code in the .A register
  2289. (same as the kernel (yes, I know that Commodore likes to call it the
  2290. "kernAl")).  Error codes 0 to 9 correspond to the standard kernel codes, error
  2291. code 10 means that the device is not a burst device, and error codes 16 to 31
  2292. correspond to the burst controller status codes 0-15.  If no error occurs, the
  2293. routines return with the carry flag clear, of course.
  2294.  
  2295. Only one file may be open at a time for Fastloading, since Fastload takes over
  2296. the disk drive and the entire serial bus.  Even regular files cannot be
  2297. accessed while a fastload is in progress.  Thus, Fastload is not suitable for
  2298. all file processing applications, but it works very well for reading a file
  2299. into memory (like for a text editor) and for summarization operations (like
  2300. word counting).  The burst library requires that the kernel and I/O space be
  2301. in context when it is called.
  2302.  
  2303. 3.1. BURST OPEN
  2304.  
  2305. The way that a burst command is given is to give a magical incantation over
  2306. the command channel to the disk drive.  You can either use the low-level
  2307. serial bus calls (LISTN, SECND, CIOUT, and UNLSN) or use the OPEN and CHROUT
  2308. calls.  I used the low level calls for a little extra zip.
  2309.  
  2310. The burst command format for Fastload is given in the back of your drive
  2311. manual:
  2312.  
  2313. .  BYTE \ bit: 7     6     5     4     3     2     1     0  | Value
  2314. . -------+--------+-----+-----+-----+-----+-----+-----+-----+-------
  2315. .   0    |     0  |  1  |  0  |  1  |  0  |  1  |  0  |  1  |  "U"
  2316. .   1    |     0  |  0  |  1  |  1  |  0  |  0  |  0  |  0  |  "0"
  2317. .   2    |     P  |  X  |  X  |  1  |  1  |  1  |  1  |  1  |  159
  2318. . 3 - ?? |                     <filename>                   |
  2319. . -------+--------------------------------------------------+-------
  2320.  
  2321. where "X" means "don't case" and "P" means "program".  If the P bit is '0'
  2322. then only program (PRG) files can be loaded, and if it is '1' then sequential
  2323. (SEQ) files can be loaded as well.  The package automatically sets this flag
  2324. for you.  Note that you don't have to do an Inquire Disk or Query Disk Format
  2325. in order to use this command like you have to do with the block reading and
  2326. writing commands.
  2327.  
  2328. If you want to try giving the incantation yourself, enter:
  2329.  
  2330. OPEN1,8,15,"U0"+CHR$(159)+"FILENAME"
  2331.  
  2332. (where "FILENAME" is the name of some file that exists on your disk) on your
  2333. 128 and your disk drive will spring to life and wait for you to read the file
  2334. data.  You can't read the data from BASIC, so to cancel the command:
  2335.  
  2336. CLOSE1
  2337.  
  2338. The "burstOpen" call of this package accepts the name of the file to be loaded
  2339. at the start of the "burstBuf" buffer, the length of the filename in the .X
  2340. register, and the device number to load the file from in the .A register.  The
  2341. burst command header and the filename are sent to the disk drive as described
  2342. above.
  2343.  
  2344. The open command also reads the first sector of the file, for two reasons.
  2345. First, the status byte returned for the first sector has special meaning.
  2346. Status code $02 means "file not found".  The package translates this into the
  2347. kernel error code.  Second, and most important, there is a bizarre feature
  2348. (read: "bug") in the Fastload command.  If the file to be read is only one
  2349. block long, then the number of bytes reported for the block length is two
  2350. bytes too short.  The following table gives the number of bytes reported and
  2351. the number of actual bytes in the sector:
  2352.  
  2353. . Actual   |    4    |    3    |    2    |    1    |    0    |
  2354. . ---------+---------+---------+---------+---------+---------+
  2355. . Reported |    2    |    1    |    0    |   255   |   255   |
  2356.  
  2357. This is where I ran into problems with Zed-128; the logic of my program
  2358. screwed up on a zero length.  I have corrected the problem here, though.  This
  2359. bug is bizarre because it only happens if the first sector is the only sector
  2360. in the file.  The reported length for all subsequent sectors is correct.  Note
  2361. also that 255 is reported for lengths of both 1 and 0.  This is because there
  2362. is no actual zero length for Commodore files.  If you OPEN1,8,2,"EMPTY" and
  2363. then immediately CLOSE1 you get a file with one carriage return character in
  2364. it.
  2365.  
  2366. The open routine calls the read routine to read a sector and if it was the
  2367. only sector of the file, the two additional bytes are burst-read and put into
  2368. the data buffer.  Note that incrementing the reported count of 255 twice gives
  2369. the correct count of 1.  Also interesting in this case is that when the
  2370. 1571/81 reports the 255, it actually transfers 255 bytes of data, all of which
  2371. are bogus.  It seems to me that they made the 1581 bug-compatible with the
  2372. 1571 in this respect.
  2373.  
  2374. The open routine also executes a SEI for reasons discussed above.  The
  2375. information returned by the open call is the same as what is returned for the
  2376. "burstRead" call discussed next.
  2377.  
  2378. 3.2. BURST READ
  2379.  
  2380. Once the Fastload command is started, the drive starts waiting to transfer the
  2381. data to you.  The transfer occurs sector by sector, with each sector preceeded
  2382. by a burst status byte.  The data is transferred using the shift register of
  2383. CIA#1 and the handshaking is done using the Slow Serial Clock line of CIA#2.
  2384. To receive a byte, you toggle the Slow Serial Clock line and wait for the
  2385. Shift Register Ready signal from CIA#1 and then read the data value from the
  2386. shift data register.
  2387.  
  2388. One of the clock registers in the CIA in the 1571/81 is used as the baud rate
  2389. generator for the serial line.  I think that it uses a delay of 4 microseconds
  2390. per bit, which gives a baud rate of 250,000 (31.25K/sec).  In my
  2391. experimentation, the maximum baud rate I have ever achieved in reality is
  2392. 200,000 (25K/sec).  I read in my 1571 Internals book that the 250,000 baud
  2393. rate cannot actually be achieved because of electrical problems that I don't
  2394. understand.  This is an important difference because the data comes flying off
  2395. the surface of the disk at around 30K/sec and if the serial bus were fast
  2396. enough, it could be transferred to the computer as it is being read.  Some
  2397. things would be so much more convenient if whomever created the universe had
  2398. thought to make light go just a little bit faster.
  2399.  
  2400. The burst handshaking protocol slows the maximum transfer rate down to about
  2401. 16K/sec.  Of course, the disk drive has more things to keep on top of than
  2402. just transferring data, so the actual burst throughput is lower than that:
  2403. about 5.4K/sec with my JiffyDOS-ified 1571 and about 7K/sec with a 1581.  Note
  2404. that you can probably increase your 1571's burst performance a bit by setting
  2405. it to use a sector interleave factor of 4, using the "U0>S"+CHR$(i) burst
  2406. command.  By default, a 1571 writes files with an interleave of 6.
  2407.  
  2408. All of the sectors before the last one will contain 254 bytes of data and the
  2409. last one will contain a specified number of bytes, from 1 to 254.  The status
  2410. code returned for the last sector is value $1F.  In this case, an additional
  2411. byte is sent before the data bytes that tells how many data bytes there will
  2412. be.  This is the value that is bugged for one-sector files as described in the
  2413. last section.  For those who like pictures, here are diagrams of the data
  2414. transferred for a sector:
  2415.  
  2416. .        REGULAR SECTOR                  LAST SECTOR OF FILE
  2417. .     +-------------------+             +--------------------+
  2418. .   0 | Burst Status Byte |           0 | Burst Status = $1F |
  2419. .     +-------------------+             +--------------------+
  2420. .   1 |                   |           1 |   Byte Count = N   |
  2421. . ... +  254 Data Bytes   |             +--------------------+
  2422. . 254 |                   |           2 |                    |
  2423. .     +-------------------+         ... |    N Data Bytes    |
  2424. .                                   N+1 |                    |
  2425. .                                       +--------------------+
  2426.  
  2427. If a sector returns a burst status code other than 0 (ok) or $1F (end), then
  2428. an error has occurred and the disk drive aborts the transfer, closes the burst
  2429. connection, and starts the drive light blinking.
  2430.  
  2431. The "burstRead" call of this package reads the data of the next sector of the
  2432. opened file into the "burstBuf" and returns the "burstStatus" and
  2433. "burstBufCount" (bytes read).  In the event of an error occuring, this routine
  2434. returns with the carry flag set and the translated burst error code in the .A
  2435. register (same as burstOpen).  When the last sector of the file has just been
  2436. read, this routine returns with a value of $1F in the "burstStatus" variable.
  2437.  
  2438. 3.3. BURST CLOSE
  2439.  
  2440. After reading the last data byte of the last sector of the file, the burst
  2441. connection and is closed automatically by the disk drive.  The "burstClose"
  2442. routine is not necessary for communication with the disk drive, but is
  2443. provided for completeness and to clear the interrupt disable bit (CLI) that
  2444. the open routine set to prevent interrupts while burst reading.
  2445.  
  2446. 3.4. PACKAGE USAGE
  2447.  
  2448. The following pseudo-code outlines how a user program is expected to use the
  2449. burst reading package:
  2450.  
  2451. .     jsr put_filename_into_burstBuf
  2452. .     ldx #filename_length
  2453. .     lda #device_number
  2454. .     jsr burstOpen
  2455. .     bcs reportError
  2456. . L1: jsr process_burstBuf_data
  2457. .     lda burstStatus
  2458. .     cmp #$1f
  2459. .     beq L2
  2460. .     jsr burstRead
  2461. .     bcc L1
  2462. .     jsr reportError
  2463. . L2: jsr burstClose
  2464.  
  2465. 4. IMPLEMENTATION
  2466.  
  2467. This section discusses the code that implements the word counting program.  It
  2468. is here in a special form; each code line is preceeded by a few special
  2469. characters and the line number.  The special characters are there to allow you
  2470. to easily extract the assembler code from the rest of this magazine (and all
  2471. of my ugly comments).  On a Unix system, all you have to do is execute the
  2472. following command line (substitute filenames as appropriate):
  2473.  
  2474. grep '^\.%...\!' Hack3 | sed 's/^.%...\!..//' | sed 's/.%...\!//' >wc.asm
  2475.  
  2476.                        
  2477. .%001!  ;Word Count utility using the burst command set's Fastload facility
  2478. .%002!  ;written 92/06/25 by Craig Bruce for C= Hacking Net Magazine
  2479. .%003!
  2480.  
  2481. The code is written for the Buddy assembler and here are a few setup
  2482. directives.
  2483.  
  2484. .%004!  .mem
  2485. .%005!  .bank 15
  2486. .%006!  .org $1c01
  2487. .%007!
  2488. .%008!  ;*** BASIC startup code
  2489. .%009!
  2490.  
  2491. This is what the "10 sys 7200" in BASIC looks like.  It is here so this
  2492. program can be executed with BASIC RUN command.
  2493.  
  2494. .%010!  .word $1c1c
  2495. .%011!  .word 10
  2496. .%012!  .byte $9e
  2497. .%013!  .asc  " 7200 : "
  2498. .%014!  .byte $8f
  2499. .%015!  .asc  " 6502 power!"
  2500. .%016!  .byte 0
  2501. .%017!  .word 0
  2502. .%018!  .word 0
  2503. .%019!
  2504. .%020!  jmp main
  2505. .%021!
  2506. .%022!  ;========== burst read library ==========
  2507. .%023!
  2508. .%024!  burstStatus = $fe
  2509. .%025!  burstBufCount = $ff
  2510. .%026!  burstBuf = $b00
  2511.  
  2512. "serialFlag" is used to determine whether a device is Fast or not, and the
  2513. "ioStatus" (a.k.a. "ST") is to tell if a device is present or not.
  2514.  
  2515. .%027!  serialFlag = $a1c
  2516. .%028!  ioStatus = $90
  2517.  
  2518. "ciaIcr" is the interrupt control register of CIA#1.  It is polled to wait for
  2519. data becoming available in the shift register ("ciaData").  "ciaSerialClk" is
  2520. the Slow serial bus clock line that is used for handshaking on the Fast bus.
  2521.  
  2522. .%029!  ciaIcr = $dc0d
  2523. .%030!  ciaSerialClk = $dd00
  2524. .%031!  ciaData = $dc0c
  2525. .%032!
  2526. .%033!  kernelListen = $ffb1
  2527. .%034!  kernelSecond = $ff93
  2528. .%035!  kernelCiout  = $ffa8
  2529. .%036!  kernelUnlsn  = $ffae
  2530. .%037!  kernelSpinp  = $ff47
  2531. .%038!
  2532.  
  2533. This is the error code value this package returns if it detects that a device
  2534. is not Fast.
  2535.  
  2536. .%039!  errNotBurstDevice = 10
  2537. .%040!
  2538. .%041!  burstFilenameLen = burstBufCount
  2539. .%042!
  2540. .%043!  burstOpen = * ;(.A=Device, burstBuf=Filename, .X=NameLen):<first block>
  2541.  
  2542. Set up for a burst open: clear the Fast flag and the device not present flag.
  2543.  
  2544. .%044!     stx burstFilenameLen
  2545. .%045!     pha
  2546. .%046!     lda serialFlag
  2547. .%047!     and #%10111111
  2548. .%048!     sta serialFlag
  2549. .%049!     lda #0
  2550. .%050!     sta ioStatus
  2551. .%051!     pla
  2552.  
  2553. Command the disk device to Listen.  Then check if the device is present or not
  2554. (bit 7 of ioStatus).  If not present, return the kernel error code.
  2555.  
  2556. .%052!     jsr kernelListen
  2557. .%053!     bit ioStatus
  2558. .%054!     bpl +
  2559. .%055!
  2560. .%056!     devNotPresent = *
  2561. .%057!     jsr kernelUnlsn
  2562. .%058!     lda #5
  2563. .%059!     sec
  2564. .%060!     rts
  2565. .%061!
  2566.  
  2567. Tell disk device to listen on the command channel (channel #15).
  2568.  
  2569. .%062!  +  lda #$6f
  2570. .%063!     jsr kernelSecond
  2571.  
  2572. Send the "U0"+CHR$(159) burst command header.
  2573.  
  2574. .%064!     lda #"u"
  2575. .%065!     jsr kernelCiout
  2576. .%066!     bit ioStatus
  2577. .%067!     bmi devNotPresent
  2578. .%068!     lda #"0"
  2579. .%069!     jsr kernelCiout
  2580. .%070!     lda #$9f
  2581. .%071!     jsr kernelCiout
  2582.  
  2583. Send the filename.
  2584.  
  2585. .%072!     ldy #0
  2586. .%073!  -  lda burstBuf,y
  2587. .%074!     jsr kernelCiout
  2588. .%075!     iny
  2589. .%076!     cpy burstFilenameLen
  2590. .%077!     bcc -
  2591.  
  2592. Finish sending the burst command and make sure the device is Fast.
  2593.  
  2594. .%078!     jsr kernelUnlsn
  2595. .%079!     lda serialFlag
  2596. .%080!     and #$40
  2597. .%081!     bne +
  2598. .%082!     sec
  2599. .%083!     lda #errNotBurstDevice
  2600. .%084!     rts
  2601. .%085!
  2602.  
  2603. Disable interrupts.
  2604.  
  2605. .%086!  +  sei
  2606.  
  2607. Prepare to receive data and signal the disk drive to start sending (by
  2608. toggling the slow serial Clock line).
  2609.  
  2610. .%087!     clc
  2611. .%088!     jsr kernelSpinp
  2612. .%089!     bit ciaIcr
  2613. .%090!     lda ciaSerialClk
  2614. .%091!     eor #$10
  2615. .%092!     sta ciaSerialClk
  2616.  
  2617. Read the first sector of the file.
  2618.  
  2619. .%093!     jsr burstRead
  2620.  
  2621. Check for errors.  Burst error code 2 (file not found) is translated to its
  2622. kernel equivalent.
  2623.  
  2624. .%094!     lda burstStatus
  2625. .%095!     cmp #2
  2626. .%096!     bcc +
  2627. .%097!     bne shortFile
  2628. .%098!     sec
  2629. .%099!     lda #4
  2630. .%100!  +  rts
  2631. .%101!
  2632.  
  2633. Check if this is a one-block file.
  2634.  
  2635. .%102!     shortFile = *
  2636. .%103!     cmp #$1f
  2637. .%104!     bne openError
  2638. .%105!     ldy burstBufCount
  2639. .%106!     ldx #2
  2640. .%107!
  2641.  
  2642. If so, we have to read the two bytes that the disk drive forgot to tell us
  2643. about.  For each byte, we wait for for the Shift Register Ready signal, toggle
  2644. the clock, and read the shift data register.  I can get away with reading the
  2645. data register after sending the acknowledge signal to the disk drive because I
  2646. am running with interrupts disabled and it could not possibly send the next
  2647. byte before I pick up the current one.  We wouldn't want any NMIs happening
  2648. while doing this, though.
  2649.  
  2650. .%108!     shortFileByte = *
  2651. .%109!     lda #$08
  2652. .%110!  -  bit ciaIcr
  2653. .%111!     beq -
  2654. .%112!     lda ciaSerialClk
  2655. .%113!     eor #$10
  2656. .%114!     sta ciaSerialClk
  2657. .%115!     lda ciaData
  2658. .%116!     sta burstBuf,y
  2659. .%117!     iny
  2660. .%118!     dex
  2661. .%119!     bne shortFileByte
  2662.  
  2663. Store the updated byte count and exit.
  2664.  
  2665. .%120!     sty burstBufCount
  2666. .%121!     clc
  2667. .%122!     rts
  2668. .%123!
  2669.  
  2670. In the event of a burst error, re-enable the interrupts since the user might
  2671. not call the burstClose routine.  Return the translated error code.
  2672.  
  2673. .%124!     openError = *
  2674. .%125!     cli
  2675. .%126!     sec
  2676. .%127!     ora #$10
  2677. .%128!     rts
  2678. .%129!
  2679.  
  2680. Read the next sector of the file.
  2681.  
  2682. .%130!  burstRead = * ;( ) : burstBuf, burstBufCount, burstStatus
  2683.  
  2684. Wait for the status byte to arrive.
  2685.  
  2686. .%131!     lda #8
  2687. .%132!  -  bit ciaIcr
  2688. .%133!     beq -
  2689.  
  2690. Toggle clock line for acknowledge.
  2691.  
  2692. .%134!     lda ciaSerialClk
  2693. .%135!     eor #$10
  2694. .%136!     sta ciaSerialClk
  2695.  
  2696. Get status byte and check.  If 2 or more and not $1F, then an error has
  2697. occurred.  If 0, then prepare to read 254 data bytes.
  2698.  
  2699. .%137!     lda ciaData
  2700. .%138!     sta burstStatus
  2701. .%139!     ldx #254
  2702. .%140!     cmp #2
  2703. .%141!     bcc actualRead
  2704. .%142!     cmp #$1f
  2705. .%143!     bne openError
  2706.  
  2707. If status byte is $1F, then get the next byte, which tells how many data bytes
  2708. are to follow.
  2709.  
  2710. .%144!     lda #8
  2711. .%145!  -  bit ciaIcr
  2712. .%146!     beq -
  2713. .%147!     ldx ciaData
  2714. .%148!     lda ciaSerialClk
  2715. .%149!     eor #$10
  2716. .%150!     sta ciaSerialClk
  2717. .%151!
  2718. .%152!     actualRead = *
  2719. .%153!     stx burstBufCount
  2720. .%154!     ldy #0
  2721. .%155!
  2722.  
  2723. Read the data bytes and put them into the burst buffer.  The clock line toggle
  2724. value is computed before receiving the data for a little extra zip.  I haven't
  2725. experimented with this, but you might be able to toggle the clock line before
  2726. receiving the data (however, probably not for the first byte).
  2727.  
  2728. .%156!     readByte = *
  2729. .%157!     lda ciaSerialClk
  2730. .%158!     eor #$10
  2731. .%159!     tax
  2732. .%160!     lda #8
  2733. .%161!  -  bit ciaIcr
  2734. .%162!     beq -
  2735. .%163!     stx ciaSerialClk
  2736. .%164!     lda ciaData
  2737. .%165!     sta burstBuf,y
  2738. .%166!     iny
  2739. .%167!     cpy burstBufCount
  2740. .%168!     bne readByte
  2741. .%169!  +  clc
  2742. .%170!     rts
  2743. .%171!
  2744.  
  2745. Close the burst package: simply CLI.
  2746.  
  2747. .%172!  burstClose = *
  2748. .%173!     cli
  2749. .%174!     clc
  2750. .%175!     rts
  2751. .%176!
  2752. .%177!  ;========== main program ==========
  2753. .%178!
  2754.  
  2755. This is the word counting application code.
  2756.  
  2757. .%179!  bkWC = $0e
  2758. .%180!  bkSelect = $ff00
  2759. .%181!  kernelChrin  = $ffcf
  2760. .%182!  kernelChrout = $ffd2
  2761. .%183!
  2762.  
  2763. The "wcInWord" is a boolean variable that tells whether the file scanner is
  2764. currently in a word or not.  The Lines, Words, and Bytes are 24-bit counters.
  2765.  
  2766. .%184!  wcInWord = 2 ;(1)
  2767. .%185!  wcLines = 3  ;(3)
  2768. .%186!  wcWords = 6  ;(3)
  2769. .%187!  wcBytes = 9  ;(3)
  2770. .%188!
  2771. .%189!  main = *
  2772.  
  2773. Put the kernel ROM and I/O space into context then initialize the counting
  2774. variables.
  2775.  
  2776. .%190!     lda #bkWC
  2777. .%191!     sta bkSelect
  2778. .%192!     jsr wcInit
  2779.  
  2780. Follow the burst reading procedure outline.
  2781.  
  2782. .%193!     jsr wcGetFilename
  2783. .%194!     jsr burstOpen
  2784. .%195!     bcc +
  2785. .%196!     jsr reportError
  2786. .%197!     rts
  2787. .%198!  /  jsr wcScanBuffer
  2788. .%199!     lda burstStatus
  2789. .%200!     cmp #$1f
  2790. .%201!     beq +
  2791. .%202!     jsr burstRead
  2792. .%203!     bcc -
  2793. .%204!     jsr reportError
  2794. .%205!  +  jsr burstClose
  2795.  
  2796. Report the numbers of lines, words, and characters and then exit.
  2797.  
  2798. .%206!     jsr wcReport
  2799. .%207!     rts
  2800. .%208!
  2801.  
  2802. Initialize the variables.
  2803.  
  2804. .%209!  wcInit = *
  2805. .%210!     lda #0
  2806. .%211!     ldx #8
  2807. .%212!  -  sta wcLines,x
  2808. .%213!     dex
  2809. .%214!     bpl -
  2810. .%215!     sta wcInWord
  2811. .%216!     rts
  2812. .%217!
  2813.  
  2814. Get the device and filename from the user.  Returns parameters suitable for
  2815. passing to burstOpen.
  2816.  
  2817. .%218!  wcGetFilename = * ;() : burstBuf=Filename, .A=Device, .X=FilenameLen
  2818.  
  2819. Display the prompt.
  2820.  
  2821. .%219!     ldx #0
  2822. .%220!  -  lda promptMsg,x
  2823. .%221!     beq +
  2824. .%222!     jsr kernelChrout
  2825. .%223!     inx
  2826. .%224!     bne -
  2827.  
  2828. Get the input line from the user.
  2829.  
  2830. .%225!  +  ldx #0
  2831. .%226!  -  jsr kernelChrin
  2832. .%227!     sta burstBuf,x
  2833. .%228!     cmp #13
  2834. .%229!     beq +
  2835. .%230!     inx
  2836. .%231!     bne -
  2837. .%232!  +  jsr kernelChrout
  2838.  
  2839. Extract the device number from the start of the input line.  If it is not
  2840. there, assume device number 8.
  2841.  
  2842. .%233!     lda #8
  2843. .%234!     cpx #2
  2844. .%235!     bcc filenameExit
  2845. .%236!     ldy burstBuf+1
  2846. .%237!     cpy #":"
  2847. .%238!     bne filenameExit
  2848. .%239!     sec
  2849. .%240!     lda burstBuf
  2850. .%241!     sbc #"a"-8
  2851. .%242!     tay
  2852.  
  2853. If a device name was present, then we have to move the rest of the filename
  2854. back over it now that we've extracted it.
  2855.  
  2856. .%243!     ldx #0
  2857. .%244!  -  lda burstBuf+2,x
  2858. .%245!     sta burstBuf,x
  2859. .%246!     cmp #13
  2860. .%247!     beq +
  2861. .%248!     inx
  2862. .%249!     bne -
  2863. .%250!  +  tya
  2864. .%251!     filenameExit = *
  2865. .%252!     rts
  2866. .%253!
  2867. .%254!     promptMsg = *
  2868. .%255!     .asc "enter filename in form filename, or a:filename, "
  2869. .%256!     .asc "or b:filename, ..."
  2870. .%257!     .byte 13
  2871. .%258!     .asc "where 'a' is for device 8, 'b' is for device 9, ..."
  2872. .%259!     .byte 13,0
  2873. .%260!
  2874.  
  2875. Scan the burst buffer after reading a sector into it.
  2876.  
  2877. .%261!  wcScanBuffer = *
  2878. .%262!     ldy #0
  2879. .%263!     cpy burstBufCount
  2880. .%264!     bne +
  2881. .%265!     rts
  2882. .%266!  +  ldx wcInWord
  2883. .%267!  -  lda burstBuf,y
  2884. .%268!  ;   jsr kernelChrout  ;uncomment this line to echo the data read
  2885. .%269!     cmp #13
  2886. .%270!     bne +
  2887.  
  2888. If the current character is a carriage return, then increment the line count.
  2889.  
  2890. .%271!     inc wcLines
  2891. .%272!     bne +
  2892. .%273!     inc wcLines+1
  2893. .%274!     bne +
  2894. .%275!     inc wcLines+2
  2895.  
  2896. If the character is a TAB, SPACE, or a RETURN, then it is a Delimiter;
  2897. otherwise, it is considered a Letter.
  2898.  
  2899. .%276!  +  cmp #33
  2900. .%277!     bcs isLetter
  2901. .%278!     cmp #" "
  2902. .%279!     beq isDelimiter
  2903. .%280!     cmp #13
  2904. .%281!     beq isDelimiter
  2905. .%282!     cmp #9
  2906. .%283!     beq isDelimiter
  2907. .%284!
  2908. .%285!     isLetter = *
  2909.  
  2910. If the character is a Letter and the previous one was a Delimiter, then
  2911. increment the word count.
  2912.  
  2913. .%286!     cpx #1
  2914. .%287!     beq scanCont
  2915. .%288!     ldx #1
  2916. .%289!     inc wcWords
  2917. .%290!     bne scanCont
  2918. .%291!     inc wcWords+1
  2919. .%292!     bne scanCont
  2920. .%293!     inc wcWords+2
  2921. .%294!     jmp scanCont
  2922. .%295!
  2923. .%296!     isDelimiter = *
  2924. .%297!     ldx #0
  2925. .%298!
  2926. .%299!     scanCont = *
  2927. .%300!     iny
  2928. .%301!     cpy burstBufCount
  2929. .%302!     bcc -
  2930.  
  2931. Add the number of bytes in the burst buffer to the total byte count for the
  2932. file.
  2933.  
  2934. .%303!     clc
  2935. .%304!     lda wcBytes
  2936. .%305!     adc burstBufCount
  2937. .%306!     sta wcBytes
  2938. .%307!     bcc +
  2939. .%308!     inc wcBytes+1
  2940. .%309!     bne +
  2941. .%310!     inc wcBytes+2
  2942. .%311!  +  stx wcInWord
  2943. .%312!     rts
  2944. .%313!
  2945.  
  2946. Report the number of lines, words, and bytes read.  Uses a "printf" type of
  2947. scheme.
  2948.  
  2949. .%314!  wcReport = *
  2950. .%315!     ldx #0
  2951. .%316!  -  lda reportMsg,x
  2952. .%317!     beq reportExit
  2953. .%318!     cmp #13
  2954. .%319!     bcs +
  2955. .%320!     stx 14
  2956. .%321!     tax
  2957. .%322!     lda 2,x
  2958. .%323!     sta 15
  2959. .%324!     lda 0,x
  2960. .%325!     ldy 1,x
  2961. .%326!     ldx 15
  2962. .%327!     jsr putnum
  2963. .%328!     ldx 14
  2964. .%329!     jmp reportCont
  2965. .%330!  +  jsr kernelChrout
  2966. .%331!     reportCont = *
  2967. .%332!     inx
  2968. .%333!     bne -
  2969. .%334!     reportExit = *
  2970. .%335!     rts
  2971. .%336!
  2972. .%337!     reportMsg = *
  2973. .%338!     .byte 13
  2974. .%339!     .asc "lines="
  2975. .%340!     .byte wcLines
  2976. .%341!     .asc ", words="
  2977. .%342!     .byte wcWords
  2978. .%343!     .asc ", chars="
  2979. .%344!     .byte wcBytes,27
  2980. .%345!     .asc "q"
  2981. .%346!     .byte 13,0
  2982. .%347!
  2983.  
  2984. Reports the error number given in the .A register.  Called after an error is
  2985. returned from a burst routine.
  2986.  
  2987. .%348!  reportError = * ;( .A=errNum )
  2988. .%349!     pha
  2989. .%350!     ldx #0
  2990. .%351!  -  lda errorMsg,x
  2991. .%352!     beq +
  2992. .%353!     jsr kernelChrout
  2993. .%354!     inx
  2994. .%355!     bne -
  2995. .%356!  +  pla
  2996. .%357!     ldy #0
  2997. .%358!     ldx #0
  2998. .%359!     jsr putnum
  2999. .%360!     lda #13
  3000. .%361!     jsr kernelChrout
  3001. .%362!     rts
  3002. .%363!
  3003. .%364!     errorMsg = *
  3004. .%365!     .asc "*** i/o error #"
  3005. .%366!     .byte 0
  3006. .%367!
  3007. .%368!  ;==========library==========
  3008. .%369!
  3009.  
  3010. Routine to print out the 24-bit number given in .AYX.
  3011.  
  3012. .%370!  libwork = $60
  3013. .%371!  itoaBin = libwork
  3014. .%372!  itoaBcd = libwork+3
  3015. .%373!  itoaFlag = libwork+7
  3016. .%374!
  3017. .%375!  putnum = *
  3018.  
  3019. Initialize binary and BCD (Binary Coded Decimal) representations of number.
  3020.  
  3021. .%376!     sta itoaBin+0
  3022. .%377!     sty itoaBin+1
  3023. .%378!     stx itoaBin+2
  3024. .%379!     ldx #3
  3025. .%380!     lda #0
  3026. .%381!  -  sta itoaBcd,x
  3027. .%382!     dex
  3028. .%383!     bpl -
  3029. .%384!     sta itoaFlag
  3030. .%385!     ldy #24
  3031. .%386!     sed
  3032. .%387!
  3033.  
  3034. Rotate each bit out of the binary number and then multiply the BCD number by
  3035. two and add the bit in.  Effectively, we are shifting the bits out of the
  3036. binary number and into the BCD representation of the number.
  3037.  
  3038. .%388!     itoaNextBit = *
  3039. .%389!     asl itoaBin+0
  3040. .%390!     rol itoaBin+1
  3041. .%391!     rol itoaBin+2
  3042. .%392!     ldx #3
  3043. .%393!  -  lda itoaBcd,x
  3044. .%394!     adc itoaBcd,x
  3045. .%395!     sta itoaBcd,x
  3046. .%396!     dex
  3047. .%397!     bpl -
  3048. .%398!     dey
  3049. .%399!     bne itoaNextBit
  3050. .%400!     cld
  3051.  
  3052. Take the BCD bytes and spit out the two digits they contain.
  3053.  
  3054. .%401!     ldx #0
  3055. .%402!     ldy #0
  3056. .%403!  -  lda itoaBcd,x
  3057. .%404!     jsr itoaPutHex
  3058. .%405!     inx
  3059. .%406!     cpx #4
  3060. .%407!     bcc -
  3061. .%408!     rts
  3062. .%409!
  3063. .%410!     itoaPutHex = *
  3064. .%411!     pha
  3065. .%412!     lsr
  3066. .%413!     lsr
  3067. .%414!     lsr
  3068. .%415!     lsr
  3069. .%416!     jsr itoaPutDigit
  3070. .%417!     pla
  3071. .%418!     and #$0f
  3072. .%419!
  3073.  
  3074. Print out the individual digits of the number.  If the current digit is zero
  3075. and all digits so far have been zero, then don't output anything, unless it is
  3076. the last digit of the number.
  3077.  
  3078. .%420!     itoaPutDigit = *
  3079. .%421!     cmp itoaFlag
  3080. .%422!     bne +
  3081. .%423!     cpy #7
  3082. .%424!     bcc itoaPutDigitExit
  3083. .%425!  +  ora #$30
  3084. .%426!     sta itoaFlag
  3085. .%427!     jsr kernelChrout
  3086. .%428!     itoaPutDigitExit = *
  3087. .%429!     iny
  3088. .%430!     rts
  3089.  
  3090. 5. UUENCODED PROGRAM
  3091.  
  3092. Here is the binary executable in uuencoded form.  The CRC32 of it is
  3093. 3676144922.  LOAD and RUN it like a regular BASIC program.
  3094.  
  3095. begin 640 wc
  3096. M`1P<'`H`GB`W,C`P(#H@CR`V-3`R(%!/5T52(0``````3!$=AO](K1P**;^-
  3097. M'`JI`(60:""Q_R20$`<@KO^I!3A@J6\@D_^I52"H_R20,.NI,""H_ZF?(*C_
  3098. MH`"Y``L@J/_(Q/^0]2"N_ZT<"BE`T`0XJ0I@>!@@1_\L#=RM`-U)$(T`W2"]
  3099. M'*7^R0*0!=`$.*D$8,D?T"&D_Z("J0@L#=SP^ZT`W4D0C0#=K0S<F0`+R,K0
  3100. MYX3_&&!8.`D08*D(+`W<\/NM`-U)$(T`W:T,W(7^HO[)`I`6R1_0W:D(+`W<
  3101. M\/NN#-RM`-U)$(T`W8;_H`"M`-U)$*JI""P-W/#[C@#=K0S<F0`+R,3_T.48
  3102. M8%@88*D.C0#_(#T=($D=(",<D`0@H!Y@(`4>I?[)'_`((+T<D/(@H!X@#AT@
  3103. M6QY@J0"B")4#RA#[A0)@H@"]C1WP!B#2_^C0]:(`(,__G0`+R0WP`^C0\R#2
  3104. MLZD(X`*0'JP!"\`ZT!<XK0`+Z3FHH@"]`@N=``O)#?`#Z-#SF&!%3E1%4B!&
  3105. M24Q%3D%-12!)3B!&3U)-($9)3$5.04U%+"!/4B!!.D9)3$5.04U%+"!/4B!"
  3106. M.D9)3$5.04U%+"`N+BX-5TA%4D4@)T$G($E3($9/4B!$159)0T4@."P@)T(G
  3107. M($E3($9/4B!$159)0T4@.2P@+BXN#0"@`,3_T`%@I@*Y``O)#=`*Y@/0!N8$
  3108. MT`+F!<DAL`S)(/`;R0WP%\D)\!/@`?`1H@'F!M`+Y@?0!^8(3$0>H@#(Q/^0
  3109. MQ1BE"67_A0F0!N8*T`+F"X8"8*(`O8(>\!_)#;`5A@ZJM0*%#[4`M`&F#R#,
  3110. M'J8.3'X>(-+_Z-#<8`U,24Y%4ST#+"!73U)$4ST&+"!#2$%24ST)&U$-`$BB
  3111. M`+V\'O`&(-+_Z-#U:*``H@`@S!ZI#2#2_V`J*BH@22]/($524D]2(",`A6"$
  3112. M889BH@.I`)5CRA#[A6>@&/@&8"9A)F*B`[5C=6.58\H0]XC0[-BB`*``M6,@
  3113. D!!_HX`20]F!(2DI*2B`/'V@I#\5GT`3`!Y`'"3"%9R#2_\A@````
  3114. `
  3115. end
  3116.  
  3117. 6. REFERENCES
  3118.  
  3119. [1] Commodore Business Machines, _Commodore_1571_Disk_Drive_User's_Guide_,
  3120.     CBM, 1985.
  3121.  
  3122. [2] Rainer Ellinger, _1571_Internals_, Abacus Software, June 1986.
  3123.  
  3124. ===============================================================================
  3125. Next Issue: (hopefully!)
  3126.  
  3127. Learning ML - Part 4
  3128.  
  3129.   In the next issue we'll embark on a project of making a space invaders style
  3130. game for the C=64/128 using the KERNAL routines we've learned.
  3131.  
  3132. The Demo Corner: FLI - more color to the screen
  3133.  
  3134.   All of us have heard complaints about the color constraints on C64.
  3135. FLI picture can have all of the 16 colors in one char position. What then
  3136. is this FLI and how it is done ?
  3137.  
  3138. The 1351 Mouse Demystified
  3139.  
  3140.   An indepth look at how the 1351 mouse operates and how to access it within
  3141. your own ML programs.  For Basic programmers, a driver for the 80 column screen
  3142. is also supplied. 
  3143.  
  3144. LITTLE RED READER: MS-DOS file reader for the 128 and 1571/81 drives.
  3145.  
  3146. This article will present a package that reads MS-DOS files and the root
  3147. directory of MS-DOS disks.  This package will use the dynamic memory allocation
  3148. package introduced in Hacking Issue #2 to allow large files to be read in.
  3149. The application-level code hasn't been finalized yet, but it will probably use
  3150. a menu-oriented full-screen display and will read and translate MS-DOS and
  3151. Commodore files. 
  3152. =============================================================================
  3153. END of Commodore Hacking Issue 3.
  3154. =============================================================================
  3155.